From e385346c53b3bb54f2e1abcb7348e33d7e075fd4 Mon Sep 17 00:00:00 2001 From: ygj6 <7699524+ygj6@users.noreply.github.com> Date: Mon, 14 Feb 2022 11:49:36 +0800 Subject: [PATCH] feat: custom manifest file name (#6667) --- docs/config/index.md | 8 ++++---- packages/vite/src/node/build.ts | 4 ++-- packages/vite/src/node/cli.ts | 4 ++-- packages/vite/src/node/plugins/manifest.ts | 5 ++++- packages/vite/src/node/ssr/ssrManifestPlugin.ts | 5 ++++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 233e08b8f864e3..ba84c49b2f5820 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -772,19 +772,19 @@ export default defineConfig({ ### build.manifest -- **Type:** `boolean` +- **Type:** `boolean | string` - **Default:** `false` - **Related:** [Backend Integration](/guide/backend-integration) - When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. + When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. When the value is a string, it will be used as the manifest file name. ### build.ssrManifest -- **Type:** `boolean` +- **Type:** `boolean | string` - **Default:** `false` - **Related:** [Server-Side Rendering](/guide/ssr) - When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. + When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. When the value is a string, it will be used as the manifest file name. ### build.ssr diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index b9936f8583b46c..c8a1a0f17fa4a4 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -179,7 +179,7 @@ export interface BuildOptions { * ``` * @default false */ - manifest?: boolean + manifest?: boolean | string /** * Build in library mode. The value should be the global name of the lib in * UMD mode. This will produce esm + cjs + umd bundle formats with default @@ -195,7 +195,7 @@ export interface BuildOptions { * Generate SSR manifest for determining style links and asset preload * directives in production. */ - ssrManifest?: boolean + ssrManifest?: boolean | string /** * Set to false to disable reporting compressed chunk sizes. * Can slightly improve build speed. diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts index 2a4f3a77918144..91b3d4e6bee998 100644 --- a/packages/vite/src/node/cli.ts +++ b/packages/vite/src/node/cli.ts @@ -149,8 +149,8 @@ cli `[boolean | "terser" | "esbuild"] enable/disable minification, ` + `or specify minifier to use (default: esbuild)` ) - .option('--manifest', `[boolean] emit build manifest json`) - .option('--ssrManifest', `[boolean] emit ssr manifest json`) + .option('--manifest [name]', `[boolean | string] emit build manifest json`) + .option('--ssrManifest [name]', `[boolean | string] emit ssr manifest json`) .option( '--emptyOutDir', `[boolean] force empty outDir when it's outside of root` diff --git a/packages/vite/src/node/plugins/manifest.ts b/packages/vite/src/node/plugins/manifest.ts index 2ce4869e67d98d..d6dceb507ca946 100644 --- a/packages/vite/src/node/plugins/manifest.ts +++ b/packages/vite/src/node/plugins/manifest.ts @@ -113,7 +113,10 @@ export function manifestPlugin(config: ResolvedConfig): Plugin { const outputLength = Array.isArray(output) ? output.length : 1 if (outputCount >= outputLength) { this.emitFile({ - fileName: `manifest.json`, + fileName: + typeof config.build.manifest === 'string' + ? config.build.manifest + : 'manifest.json', type: 'asset', source: JSON.stringify(manifest, null, 2) }) diff --git a/packages/vite/src/node/ssr/ssrManifestPlugin.ts b/packages/vite/src/node/ssr/ssrManifestPlugin.ts index e6811eae29b210..a92550e39d4ed0 100644 --- a/packages/vite/src/node/ssr/ssrManifestPlugin.ts +++ b/packages/vite/src/node/ssr/ssrManifestPlugin.ts @@ -96,7 +96,10 @@ export function ssrManifestPlugin(config: ResolvedConfig): Plugin { } this.emitFile({ - fileName: 'ssr-manifest.json', + fileName: + typeof config.build.ssrManifest === 'string' + ? config.build.ssrManifest + : 'ssr-manifest.json', type: 'asset', source: JSON.stringify(ssrManifest, null, 2) })