@@ -6,7 +6,7 @@ import rawModules from '@kkt/raw-modules';
6
6
import scopePluginOptions from '@kkt/scope-plugin-options' ;
7
7
import pkg from './package.json' ;
8
8
9
- export default ( conf : Configuration , env : string , options : LoaderConfOptions ) => {
9
+ export default ( conf : Configuration , env : 'production' | 'development' , options : LoaderConfOptions ) => {
10
10
conf = lessModules ( conf , env , options ) ;
11
11
conf = rawModules ( conf , env , { ...options } ) ;
12
12
conf = scopePluginOptions ( conf , env , {
@@ -19,118 +19,46 @@ export default (conf: Configuration, env: string, options: LoaderConfOptions) =>
19
19
conf . plugins ! . push ( new webpack . DefinePlugin ( {
20
20
VERSION : JSON . stringify ( pkg . version ) ,
21
21
} ) ) ;
22
- conf . optimization = {
23
- ...conf . optimization ,
24
- splitChunks : {
25
- chunks : 'all' , // async对异步引入的代码分割 initial 对同步引入代码分割 all对同步异步引入的分割都开启
26
- minSize : 30000 , // 字节 引入的文件大于30kb才进行分割
27
- maxSize : 0 , // 文件的最大尺寸,优先级:maxInitialRequest/maxAsyncRequests < maxSize < minSize,需要注意的是这个如果配置了,umi.js 就可能被拆开,最后构建出来的 chunkMap 中可能就找不到 umi.js 了
28
- minChunks : 1 , // 模块至少使用次数
29
- maxAsyncRequests : 30 , // 同时加载的模块数量最多是_个,只分割出同时引入的前_个文件(按需加载模块)
30
- maxInitialRequests : 25 , // 首页加载的时候引入的文件最多 _ 个(加载初始页面)
31
- automaticNameDelimiter : '~' , // 缓存组和生成文件名称之间的连接符
32
- name : true , // 缓存组里面的 filename 生效,覆盖默认命名
33
- cacheGroups : {
34
- markdown_preview : {
35
- name : 'vendors-markdown-preview' ,
36
- chunks : 'all' ,
37
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ u i w \/ r e a c t - m a r k d o w n - p r e v i e w | c o d e m i r r o r ) [ \\ / ] / ,
38
- priority : - 2 ,
39
- } ,
40
- prismjs : {
41
- name : 'vendors-prismjs' ,
42
- chunks : 'all' ,
43
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( p r i s m j s ) [ \\ / ] / ,
44
- priority : - 2 ,
45
- } ,
46
- react_code_preview : {
47
- name : 'vendors-code-preview' ,
48
- chunks : 'all' ,
49
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ u i w \/ r e a c t - c o d e - p r e v i e w ) [ \\ / ] / ,
50
- priority : - 2 ,
51
- } ,
52
- react : {
53
- name : 'vendors-react' ,
54
- chunks : 'all' ,
55
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( r e a c t | r e a c t - d o m | r e a c t - r o u t e r - d o m ) [ \\ / ] / ,
56
- priority : - 5 ,
57
- } ,
58
- lodash : {
59
- name : 'vendors-lodash' ,
60
- chunks : 'all' ,
61
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( l o d a s h ) [ \\ / ] / ,
62
- priority : - 5 ,
63
- } ,
64
- babel_plugin : {
65
- name : 'babel_plugin' ,
66
- chunks : 'all' ,
67
- // test: /[\\/]node_modules[\\/](babel-plugin-transform-remove-imports)[\\/]/,
68
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( b a b e l - ? .* ) [ \\ / ] / ,
69
- priority : - 5 ,
70
- } ,
71
- // babel_runtime: {
72
- // name: 'vendors-runtime',
73
- // chunks: 'all',
74
- // test: /[\\/]node_modules[\\/](@babel)[\\/]/,
75
- // priority: -5,
76
- // },
77
- babel_standalone : {
78
- name : 'vendors-standalone' ,
79
- chunks : 'all' ,
80
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ s t a n d a l o n e ) [ \\ / ] / ,
81
- priority : - 5 ,
82
- } ,
83
- babel_runtime_template : {
84
- name : 'vendors-runtime-template' ,
85
- chunks : 'all' ,
86
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] @ b a b e l [ \/ ] ( t e m p l a t e | r e g e n e r a t o r | h i g h l i g h t | p a r s e r | c o d e - f r a m e | p l u g i n - t r a n s f o r m - c l a s s e s ) [ \\ / ] / ,
87
- priority : - 5 ,
88
- } ,
89
- babel_runtime_core : {
90
- name : 'vendors-runtime-core' ,
91
- chunks : 'all' ,
92
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ c o r e ) [ \\ / ] / ,
93
- priority : - 5 ,
94
- } ,
95
- babel_remark : {
96
- name : 'vendors-remark' ,
97
- chunks : 'all' ,
98
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( r e m a r k - p a r s e ) [ \\ / ] / ,
99
- priority : - 5 ,
100
- } ,
101
- babel_runtime_generator : {
102
- name : 'vendors-runtime-generator' ,
103
- chunks : 'all' ,
104
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ g e n e r a t o r ) [ \\ / ] / ,
105
- priority : - 5 ,
106
- } ,
107
- babel_helper : {
108
- name : 'vendors-helper' ,
109
- chunks : 'all' ,
110
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ h e l p e r ? .* ) [ \\ / ] / ,
111
- priority : - 5 ,
112
- } ,
113
- babel_runtime_helpers : {
114
- name : 'vendors-runtime-helpers' ,
115
- chunks : 'all' ,
116
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ r u n t i m e \/ h e l p e r s ) [ \\ / ] / ,
117
- priority : - 5 ,
118
- } ,
119
- babel_runtime_types : {
120
- name : 'vendors-runtime-types' ,
121
- chunks : 'all' ,
122
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ t y p e s ) [ \\ / ] / ,
123
- priority : - 5 ,
124
- } ,
125
- babel_runtime_traverse : {
126
- name : 'vendors-runtime-traverse' ,
127
- chunks : 'all' ,
128
- test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l \/ t r a v e r s e ) [ \\ / ] / ,
129
- priority : - 5 ,
22
+ if ( env === 'production' ) {
23
+ conf . output = { ...conf . output , publicPath : './' } ;
24
+ conf . optimization = {
25
+ ...conf . optimization ,
26
+ splitChunks : {
27
+ cacheGroups : {
28
+ reactvendor : {
29
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( r e a c t | r e a c t - d o m ) [ \\ / ] / ,
30
+ name : 'react-vendor' ,
31
+ chunks : 'all' ,
32
+ } ,
33
+ babelstandalone : {
34
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ b a b e l [ \\ / ] s t a n d a l o n e ) [ \\ / ] / ,
35
+ name : 'babel-standalone-vendor' ,
36
+ chunks : 'all' ,
37
+ } ,
38
+ prismjs : {
39
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( r e f r a c t o r ) [ \\ / ] / ,
40
+ name : 'refractor-vendor' ,
41
+ chunks : 'all' ,
42
+ } ,
43
+ codemirror : {
44
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ c o d e m i r r o r ) [ \\ / ] / ,
45
+ name : 'codemirror-vendor' ,
46
+ chunks : 'all' ,
47
+ } ,
48
+ uiw : {
49
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( @ u i w ) [ \\ / ] / ,
50
+ name : 'uiw-vendor' ,
51
+ chunks : 'all' ,
52
+ } ,
53
+ parse5 : {
54
+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] ( p a r s e 5 ) [ \\ / ] / ,
55
+ name : 'parse5-vendor' ,
56
+ chunks : 'all' ,
57
+ } ,
130
58
} ,
131
59
} ,
132
- } ,
133
- } ;
60
+ } ;
61
+ }
134
62
135
63
return conf ;
136
64
}
0 commit comments