diff --git a/.changeset/fuzzy-pots-destroy.md b/.changeset/fuzzy-pots-destroy.md new file mode 100644 index 0000000..d816c83 --- /dev/null +++ b/.changeset/fuzzy-pots-destroy.md @@ -0,0 +1,5 @@ +--- +'vite-plugin-static-copy': patch +--- + +copy only once even if multiple bundles are generated diff --git a/src/build.ts b/src/build.ts index 81d1613..62c8223 100644 --- a/src/build.ts +++ b/src/build.ts @@ -8,6 +8,7 @@ export const buildPlugin = ({ silent }: ResolvedViteStaticCopyOptions): Plugin => { let config: ResolvedConfig + let output = false return { name: 'vite-plugin-static-copy:build', @@ -15,7 +16,15 @@ export const buildPlugin = ({ configResolved(_config) { config = _config }, + buildEnd() { + // reset for watch mode + output = false + }, async writeBundle() { + // run copy only once even if multiple bundles are generated + if (output) return + output = true + const result = await copyAll( config.root, config.build.outDir,