diff --git a/docs/config/build-options.md b/docs/config/build-options.md index da1d33d453e8d1..2c60c838fa54ee 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -209,6 +209,14 @@ Set to `false` to disable writing the bundle to disk. This is mostly used in [pr By default, Vite will empty the `outDir` on build if it is inside project root. It will emit a warning if `outDir` is outside of root to avoid accidentally removing important files. You can explicitly set this option to suppress the warning. This is also available via command line as `--emptyOutDir`. +## build.copyPublicDir + +- **Experimental** +- **Type:** `boolean` +- **Default:** `true` + +By default, Vite will copy files from the `publicDir` into the `outDir` on build. Set to `false` to disable this. + ## build.reportCompressedSize - **Type:** `boolean` diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 94f08c14b17b64..f4c14834a2380f 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -158,6 +158,12 @@ export interface BuildOptions { * @default true when outDir is a sub directory of project root */ emptyOutDir?: boolean | null + /** + * Copy the public directory to outDir on write. + * @default true + * @experimental + */ + copyPublicDir?: boolean /** * Whether to emit a manifest.json under assets dir to map hash-less filenames * to their hashed versions. Useful when you want to generate your own HTML @@ -308,6 +314,7 @@ export function resolveBuildOptions( terserOptions: {}, write: true, emptyOutDir: null, + copyPublicDir: true, manifest: false, lib: false, ssr: false, @@ -687,7 +694,11 @@ function prepareOutDir( .filter(Boolean) emptyDir(outDir, [...skipDirs, '.git']) } - if (config.publicDir && fs.existsSync(config.publicDir)) { + if ( + config.build.copyPublicDir && + config.publicDir && + fs.existsSync(config.publicDir) + ) { copyDir(config.publicDir, outDir) } }