@@ -49,27 +49,34 @@ const options = {
4949 } ,
5050 // 性能优化:启用缓存加速二次构建
5151 cache : true ,
52-
52+
5353 // 并行处理优化
5454 maxParallelFileOps : 20 ,
55-
55+
5656 // Tree-shake 配置 - 平衡优化和兼容性
5757 treeshake : {
58- // 只标记明确的副作用模块
58+ // 标记模块副作用
5959 moduleSideEffects : ( id ) => {
6060 // CSS 文件有副作用
6161 if ( id . endsWith ( '.css' ) ) return true ;
62- // 对第三方库保持保守,避免错误 tree-shake
63- if ( id . includes ( 'node_modules/' ) ) {
64- // crypto-js、mermaid、echarts 等库在 tree-shake 时会出问题
65- if ( id . includes ( 'crypto-js' ) || id . includes ( 'mermaid' ) || id . includes ( 'echarts' ) ) {
66- return true ;
67- }
68- // prismjs 及其组件有副作用(将语言注册到 Prism.languages)
69- if ( id . includes ( 'prismjs' ) ) {
70- return true ;
71- }
62+
63+ // 源代码模块默认有副作用,避免错误 tree-shake
64+ // 源代码不在 node_modules 中
65+ if ( ! id . includes ( 'node_modules' ) ) {
66+ return true ;
67+ }
68+
69+ // 对特定第三方库保持保守,避免错误 tree-shake
70+ // crypto-js、mermaid、echarts 等库在 tree-shake 时会出问题
71+ if ( id . includes ( 'crypto-js' ) || id . includes ( 'mermaid' ) || id . includes ( 'echarts' ) ) {
72+ return true ;
7273 }
74+ // prismjs 及其组件有副作用(将语言注册到 Prism.languages)
75+ if ( id . includes ( 'prismjs' ) ) {
76+ return true ;
77+ }
78+
79+ // 其他 node_modules 可以安全地 tree-shake
7380 return false ;
7481 } ,
7582 // 禁用属性读取副作用检查,确保 Prism.languages 赋值不被优化掉
@@ -119,13 +126,13 @@ const options = {
119126
120127 // 优化:忽略动态 require
121128 ignoreDynamicRequires : true ,
122-
129+
123130 // 性能优化:严格模式检查
124131 strictRequires : 'auto' ,
125-
132+
126133 // 默认导出模式
127134 defaultIsModuleExports : 'auto' ,
128-
135+
129136 // 要求语义
130137 requireReturnsDefault : 'auto' ,
131138 } ) ,
0 commit comments