Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): add copyPublicDir option #10550

Merged
merged 4 commits into from Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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