diff --git a/.gitignore b/.gitignore index 9c62828..83ec3db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ node_modules coverage dist +.idea +.DS_Store +.vscode +yarn-debug.log* +yarn-error.log* \ No newline at end of file diff --git a/readme.md b/readme.md index 2ba3a8d..b5ecfde 100644 --- a/readme.md +++ b/readme.md @@ -39,6 +39,10 @@ export default { } ``` +**Note**: if you're using any kind of clean/delete plugins, such as [rollup-plugin-del](https://www.npmjs.com/package/rollup-plugin-del), +which remove any of the destination folders, ensure that this plugin is run **after** that plugin, otherwise the copied files might +accidentally be deleted. + ### Configuration There are some useful options: diff --git a/src/index.js b/src/index.js index 95ecc92..f63f875 100644 --- a/src/index.js +++ b/src/index.js @@ -112,8 +112,16 @@ export default function copy(options = {}) { const { contents, dest, src, transformed } = copyTarget if (transformed) { + if (!fs.existsSync(path.dirname(dest))) { + fs.mkdirSync(path.dirname(dest), { recursive: true }) + } + await fs.outputFile(dest, contents, restPluginOptions) } else { + if (!fs.existsSync(path.dirname(dest))) { + fs.mkdirSync(path.dirname(dest), { recursive: true }) + } + await fs.copy(src, dest, restPluginOptions) }