Skip to content

Commit 4f4a39f

Browse files
authoredOct 26, 2022
feat(build): experimental copyPublicDir option (#10550)
1 parent 15b90b3 commit 4f4a39f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎docs/config/build-options.md

+8
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ Set to `false` to disable writing the bundle to disk. This is mostly used in [pr
209209
210210
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`.
211211
212+
## build.copyPublicDir
213+
214+
- **Experimental**
215+
- **Type:** `boolean`
216+
- **Default:** `true`
217+
218+
By default, Vite will copy files from the `publicDir` into the `outDir` on build. Set to `false` to disable this.
219+
212220
## build.reportCompressedSize
213221
214222
- **Type:** `boolean`

‎packages/vite/src/node/build.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ export interface BuildOptions {
158158
* @default true when outDir is a sub directory of project root
159159
*/
160160
emptyOutDir?: boolean | null
161+
/**
162+
* Copy the public directory to outDir on write.
163+
* @default true
164+
* @experimental
165+
*/
166+
copyPublicDir?: boolean
161167
/**
162168
* Whether to emit a manifest.json under assets dir to map hash-less filenames
163169
* to their hashed versions. Useful when you want to generate your own HTML
@@ -308,6 +314,7 @@ export function resolveBuildOptions(
308314
terserOptions: {},
309315
write: true,
310316
emptyOutDir: null,
317+
copyPublicDir: true,
311318
manifest: false,
312319
lib: false,
313320
ssr: false,
@@ -687,7 +694,11 @@ function prepareOutDir(
687694
.filter(Boolean)
688695
emptyDir(outDir, [...skipDirs, '.git'])
689696
}
690-
if (config.publicDir && fs.existsSync(config.publicDir)) {
697+
if (
698+
config.build.copyPublicDir &&
699+
config.publicDir &&
700+
fs.existsSync(config.publicDir)
701+
) {
691702
copyDir(config.publicDir, outDir)
692703
}
693704
}

0 commit comments

Comments
 (0)
Please sign in to comment.