瀏覽代碼

chore: split chunk

dragooncjw 10 月之前
父節點
當前提交
b449e4672e
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      apps/docs/rspress.config.ts

+ 17 - 0
apps/docs/rspress.config.ts

@@ -11,6 +11,23 @@ export default defineConfig({
   builderConfig: {
   builderConfig: {
     tools: {
     tools: {
       rspack: {
       rspack: {
+        optimization: {
+          splitChunks: {
+            chunks: 'all', // 拆分所有模块,包括异步和同步
+            minSize: 30 * 1024, // 30KB 以下不拆分
+            maxSize: 500 * 1024, // 500KB 以上强制拆分
+            minChunks: 1, // 最少被引用 1 次就可以拆分
+            automaticNameDelimiter: '-',
+            cacheGroups: {
+              vendors: {
+                test: /[\\/]node_modules[\\/]/,
+                name: 'vendors',
+                chunks: 'all',
+                priority: -10, // 优先级
+              },
+            },
+          },
+        },
         // 禁用 ES 模块输出(启用 CommonJS)
         // 禁用 ES 模块输出(启用 CommonJS)
         experiments: {
         experiments: {
           outputModule: false,
           outputModule: false,