Skip to content

Commit

Permalink
feat(build): experimental copyPublicDir option (#10550)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Oct 26, 2022
1 parent 15b90b3 commit 4f4a39f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/config/build-options.md
Expand Up @@ -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`
Expand Down
13 changes: 12 additions & 1 deletion packages/vite/src/node/build.ts
Expand Up @@ -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
Expand Down Expand Up @@ -308,6 +314,7 @@ export function resolveBuildOptions(
terserOptions: {},
write: true,
emptyOutDir: null,
copyPublicDir: true,
manifest: false,
lib: false,
ssr: false,
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 4f4a39f

Please sign in to comment.