Skip to content

Commit

Permalink
feat: custom manifest file name (#6667)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Feb 14, 2022
1 parent 2eabcb9 commit e385346
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions docs/config/index.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/cli.ts
Expand Up @@ -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`
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/plugins/manifest.ts
Expand Up @@ -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)
})
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/node/ssr/ssrManifestPlugin.ts
Expand Up @@ -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)
})
Expand Down

0 comments on commit e385346

Please sign in to comment.