Skip to content

Commit 7a1a4e0

Browse files
authored
chore: preEntry to ensures css order and splitChunks for perf (#2714)
1 parent 2b479ff commit 7a1a4e0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/core/src/node/initRsbuild.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ async function createInternalBuildConfig(
258258
},
259259
},
260260
source: {
261+
preEntry: [
262+
// ensure CSS orders and access @theme before @rspress/theme-default to avoid circular dependency
263+
path.join(DEFAULT_THEME, './styles/index.js'), // 1. @rspress/theme-default global styles
264+
'virtual-global-styles', // 2. virtual-global-styles
265+
'@theme', // 3. import './index.css'; from 'theme/index.tsx'
266+
],
261267
include: [PACKAGE_ROOT],
262268
define: {
263269
'process.env.TEST': JSON.stringify(process.env.TEST),
@@ -369,20 +375,20 @@ async function createInternalBuildConfig(
369375
.test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/)
370376
.merge({ sideEffects: true });
371377

378+
if (isSsg || isSsgMd) {
379+
chain.optimization.splitChunks({});
380+
}
381+
372382
if (isSsg) {
373383
chain.output.filename(
374384
`${NODE_SSG_BUNDLE_FOLDER}/${NODE_SSG_BUNDLE_NAME}`,
375385
);
376386
chain.output.chunkFilename(`${NODE_SSG_BUNDLE_FOLDER}/[name].cjs`);
377-
// For perf
378-
chain.output.set('asyncChunks', false);
379387
} else if (isSsgMd) {
380388
chain.output.filename(
381389
`${NODE_SSG_MD_BUNDLE_FOLDER}/${NODE_SSG_MD_BUNDLE_NAME}`,
382390
);
383391
chain.output.chunkFilename(`${NODE_SSG_MD_BUNDLE_FOLDER}/[name].cjs`);
384-
// For perf
385-
chain.output.set('asyncChunks', false);
386392
}
387393
},
388394
},
@@ -399,10 +405,6 @@ async function createInternalBuildConfig(
399405
index:
400406
enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY,
401407
},
402-
preEntry: [
403-
path.join(DEFAULT_THEME, './styles/index.js'),
404-
'virtual-global-styles',
405-
],
406408
define: {
407409
'process.env.__SSR__': JSON.stringify(false),
408410
'process.env.__SSR_MD__': JSON.stringify(false),

0 commit comments

Comments
 (0)