@@ -13,12 +13,11 @@ const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
13
13
const webpackConfig = merge ( baseWebpackConfig , {
14
14
entry : {
15
15
'theme-dark' : './src/assets/css/theme-dark.scss' ,
16
- 'theme-green ' : './src/assets/css/theme-green .scss'
16
+ 'theme-default ' : './src/assets/css/theme-default .scss'
17
17
} ,
18
18
module : {
19
19
rules : utils . styleLoaders ( {
20
- sourceMap : config . build . productionSourceMap ,
21
- extract : true
20
+ sourceMap : config . build . productionSourceMap
22
21
} )
23
22
} ,
24
23
devtool : config . build . productionSourceMap ? '#source-map' : false ,
@@ -28,21 +27,73 @@ const webpackConfig = merge(baseWebpackConfig, {
28
27
chunkFilename : utils . assetsPath ( 'js/[name].[chunkhash:7].js' )
29
28
} ,
30
29
mode : "production" ,
30
+ // 文件压缩及chunk分离
31
+ // https://github.com/webpack/webpack/issues/6409
32
+ // https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
33
+ optimization : {
34
+ minimize : true ,
35
+ runtimeChunk : true ,
36
+ splitChunks : {
37
+ // chunks: "async",
38
+ // maxAsyncRequests: 5,
39
+ // maxInitialRequests: 3,
40
+ chunks : 'all' ,
41
+ minSize : 0 ,
42
+ maxAsyncRequests : Infinity ,
43
+ maxInitialRequests : Infinity ,
44
+ name : true ,
45
+ cacheGroups : {
46
+ default : {
47
+ chunks : 'async' ,
48
+ maxAsyncRequests : 5 ,
49
+ maxInitialRequests : 3 ,
50
+ priority : - 20 ,
51
+ reuseExistingChunk : true ,
52
+ } ,
53
+ css : {
54
+ name : function ( el ) {
55
+ console . log ( el )
56
+ return utils . assetsPath ( 'css/' + el . name + '.' + el . hash + '.css' )
57
+ } ,
58
+ test : / \. ( c s s | s a s s | s c s s | l e s s ) ( \? .* ) ? $ / ,
59
+ chunks : 'all'
60
+ } ,
61
+ echarts : {
62
+ name : 'echarts' ,
63
+ enforce : true ,
64
+ test : function ( module ) {
65
+ var context = module . context ;
66
+ return context && ( context . indexOf ( 'echarts' ) >= 0 || context . indexOf ( 'zrender' ) >= 0 )
67
+ }
68
+ } ,
69
+ vendors : {
70
+ name : 'vendors' ,
71
+ enforce : true ,
72
+ test : function ( module ) {
73
+ return (
74
+ module . resource &&
75
+ / \. j s $ / . test ( module . resource ) &&
76
+ module . resource . indexOf (
77
+ path . join ( __dirname , '../node_modules' )
78
+ ) === 0
79
+ )
80
+ } ,
81
+ chunks : "all"
82
+ }
83
+
84
+ // commons: {
85
+ // test: /[\\/]node_modules[\\/]/,
86
+ // name: "vendors",
87
+ // chunks: "all"
88
+ // }
89
+ }
90
+ }
91
+ } ,
31
92
plugins : [
32
- // http://vuejs.github.io/vue-loader/en/workflow/production.html
33
- // new webpack.DefinePlugin({
34
- // 'process.env': env
35
- // }),
36
- new webpack . optimize . UglifyJsPlugin ( {
37
- compress : {
38
- warnings : false
39
- } ,
40
- sourceMap : false
41
- } ) ,
42
93
// extract css into its own file
43
- new ExtractTextPlugin ( {
44
- filename : utils . assetsPath ( 'css/[name].[contenthash:7].css' )
45
- } ) ,
94
+ // new ExtractTextPlugin({
95
+ // filename: utils.assetsPath('css/[name].[contenthash:7].css')
96
+ // }),
46
97
// Compress extracted CSS. We are using this plugin so that possible
47
98
// duplicated CSS from different components can be deduped.
48
99
new OptimizeCSSPlugin ( {
@@ -67,38 +118,38 @@ const webpackConfig = merge(baseWebpackConfig, {
67
118
minify : false ,
68
119
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
69
120
chunksSortMode : 'dependency' ,
70
- excludeChunks : [ 'theme-default' , 'theme-green ' ]
121
+ excludeChunks : [ 'theme-default' , 'theme-dark ' ]
71
122
} ) ,
72
123
// keep module.id stable when vender modules does not change
73
124
new webpack . HashedModuleIdsPlugin ( ) ,
74
125
// split vendor js into its own file
75
- new webpack . optimize . CommonsChunkPlugin ( {
76
- name : 'vendor' ,
77
- minChunks : function ( module ) {
78
- // any required modules inside node_modules are extracted to vendor
79
- return (
80
- module . resource &&
81
- / \. j s $ / . test ( module . resource ) &&
82
- module . resource . indexOf (
83
- path . join ( __dirname , '../node_modules' )
84
- ) === 0
85
- )
86
- }
87
- } ) ,
126
+ // new webpack.optimize.CommonsChunkPlugin({
127
+ // name: 'vendor',
128
+ // minChunks: function(module) {
129
+ // // any required modules inside node_modules are extracted to vendor
130
+ // return (
131
+ // module.resource &&
132
+ // /\.js$/.test(module.resource) &&
133
+ // module.resource.indexOf(
134
+ // path.join(__dirname, '../node_modules')
135
+ // ) === 0
136
+ // )
137
+ // }
138
+ // }),
88
139
// split echarts into its own file
89
- new webpack . optimize . CommonsChunkPlugin ( {
90
- async : [ 'echarts' ] ,
91
- minChunks ( module ) {
92
- var context = module . context ;
93
- return context && ( context . indexOf ( 'echarts' ) >= 0 || context . indexOf ( 'zrender' ) >= 0 ) ;
94
- }
95
- } ) ,
140
+ // new webpack.optimize.CommonsChunkPlugin({
141
+ // async: ['echarts'],
142
+ // minChunks(module) {
143
+ // var context = module.context;
144
+ // return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0);
145
+ // }
146
+ // }),
96
147
// extract webpack runtime and module manifest to its own file in order to
97
148
// prevent vendor hash from being updated whenever app bundle is updated
98
- new webpack . optimize . CommonsChunkPlugin ( {
99
- name : 'manifest' ,
100
- chunks : [ 'vendor' ]
101
- } ) ,
149
+ // new webpack.optimize.CommonsChunkPlugin({
150
+ // name: 'manifest',
151
+ // chunks: ['vendor']
152
+ // }),
102
153
// copy custom static assets
103
154
new CopyWebpackPlugin ( [
104
155
{
0 commit comments