File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
packages/astro/src/core/build/plugins Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
4141 const pagesToCss : Record < string , Record < string , { order : number ; depth : number } > > = { } ;
4242 // Map of module Ids (usually something like `/Users/...blog.mdx?astroPropagatedAssets`) to its imported CSS
4343 const moduleIdToPropagatedCss : Record < string , Set < string > > = { } ;
44+ // Keep track of CSS that has been bundled to avoid duplication between ssr and prerender.
45+ const cssModulesInBundles = new Set ( ) ;
4446
4547 const cssBuildPlugin : VitePlugin = {
4648 name : 'astro:rollup-plugin-build-css' ,
@@ -49,6 +51,21 @@ function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[] {
4951 return environment . name === 'client' || environment . name === 'ssr' || environment . name === 'prerender' ;
5052 } ,
5153
54+ transform ( _code , id ) {
55+ if ( isCSSRequest ( id ) ) {
56+ // In prerender, don't rebundle CSS that was already bundled in SSR.
57+ // Return an empty string here to prevent it.
58+ if ( this . environment . name === 'prerender' ) {
59+ if ( cssModulesInBundles . has ( id ) ) {
60+ return {
61+ code : ''
62+ }
63+ }
64+ }
65+ cssModulesInBundles . add ( id ) ;
66+ }
67+ } ,
68+
5269 async generateBundle ( _outputOptions , bundle ) {
5370 // Collect CSS modules that were bundled during SSR build for deduplication in client build
5471 if ( this . environment ?. name === 'ssr' || this . environment ?. name === 'prerender' ) {
You can’t perform that action at this time.
0 commit comments