Skip to content

Commit

Permalink
chore: add build.ssrEmitAssets experimental option
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jan 25, 2023
1 parent a1ad5a2 commit 7b8b0f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ export interface BuildOptions {
* directives in production.
*/
ssrManifest?: boolean | string
/**
* Emit assets during SSR.
* @experimental
* @default false
*/
ssrEmitAssets?: boolean
/**
* Set to false to disable reporting compressed chunk sizes.
* Can slightly improve build speed.
Expand Down Expand Up @@ -324,6 +330,7 @@ export function resolveBuildOptions(
lib: false,
ssr: false,
ssrManifest: false,
ssrEmitAssets: false,
reportCompressedSize: true,
chunkSizeWarningLimit: 500,
watch: null,
Expand Down
20 changes: 20 additions & 0 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const assetUrlRE = /__VITE_ASSET__([a-z\d]+)__(?:\$_(.*?)__)?/g

const rawRE = /(?:\?|&)raw(?:&|$)/
const urlRE = /(\?|&)url(?:&|$)/
const jsSourceMapRE = /\.[cm]?js\.map$/

const assetCache = new WeakMap<ResolvedConfig, Map<string, string>>()

Expand Down Expand Up @@ -183,6 +184,25 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
return null
}
},

generateBundle(_, bundle) {
// do not emit assets for SSR build
if (
config.command === 'build' &&
config.build.ssr &&
!config.build.ssrEmitAssets
) {
for (const file in bundle) {
if (
bundle[file].type === 'asset' &&
!file.endsWith('ssr-manifest.json') &&
!jsSourceMapRE.test(file)
) {
delete bundle[file]
}
}
}
},
}
}

Expand Down

0 comments on commit 7b8b0f9

Please sign in to comment.