From 3d7fae03ee7d3862020f18e1d0f4d8d4c4f5f443 Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 20 Oct 2022 20:01:25 +0800 Subject: [PATCH 1/3] feat(build): add copyPublicDir option --- packages/vite/src/node/build.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 94f08c14b17b64..29b201d33b539a 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -158,6 +158,11 @@ 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 + */ + 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 +313,7 @@ export function resolveBuildOptions( terserOptions: {}, write: true, emptyOutDir: null, + copyPublicDir: true, manifest: false, lib: false, ssr: false, @@ -687,7 +693,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) } } From 117c6f0decde141c019478b47b17ce48bc1444b3 Mon Sep 17 00:00:00 2001 From: bluwy Date: Thu, 20 Oct 2022 20:16:07 +0800 Subject: [PATCH 2/3] docs: add doc --- docs/config/build-options.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/config/build-options.md b/docs/config/build-options.md index da1d33d453e8d1..7ba882d2869045 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -209,6 +209,13 @@ 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 + +- **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` From 854c175431967b15ac69eb08889c1ab250375712 Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 26 Oct 2022 17:19:33 +0800 Subject: [PATCH 3/3] chore: add experimental flag --- docs/config/build-options.md | 1 + packages/vite/src/node/build.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/config/build-options.md b/docs/config/build-options.md index 7ba882d2869045..2c60c838fa54ee 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -211,6 +211,7 @@ By default, Vite will empty the `outDir` on build if it is inside project root. ## build.copyPublicDir +- **Experimental** - **Type:** `boolean` - **Default:** `true` diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 29b201d33b539a..f4c14834a2380f 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -161,6 +161,7 @@ export interface BuildOptions { /** * Copy the public directory to outDir on write. * @default true + * @experimental */ copyPublicDir?: boolean /**