feat: custom manifest file name (#6667)

This commit is contained in:
ygj6 2022-02-14 11:49:36 +08:00 committed by GitHub
parent 2eabcb9a30
commit e385346c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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.

View File

@ -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`

View File

@ -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)
})

View File

@ -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)
})