@@ -7,17 +7,29 @@ const merge = require('webpack-merge')
7
7
const baseWebpackConfig = require ( './webpack.base.conf' )
8
8
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' )
9
9
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' )
10
- const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' )
10
+ const UglifyJsPlugin = require ( "uglifyjs-webpack-plugin" )
11
+ const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' )
11
12
const OptimizeCSSPlugin = require ( 'optimize-css-assets-webpack-plugin' )
12
13
14
+ function recursiveIssuer ( m ) {
15
+ if ( m . issuer ) {
16
+ return recursiveIssuer ( m . issuer ) ;
17
+ } else if ( m . name ) {
18
+ return m . name ;
19
+ } else {
20
+ return false ;
21
+ }
22
+ }
23
+
13
24
const webpackConfig = merge ( baseWebpackConfig , {
14
25
entry : {
15
26
'theme-dark' : './src/assets/css/theme-dark.scss' ,
16
27
'theme-default' : './src/assets/css/theme-default.scss'
17
28
} ,
18
29
module : {
19
30
rules : utils . styleLoaders ( {
20
- sourceMap : config . build . productionSourceMap
31
+ sourceMap : config . build . productionSourceMap ,
32
+ extract : true
21
33
} )
22
34
} ,
23
35
devtool : config . build . productionSourceMap ? '#source-map' : false ,
@@ -31,13 +43,18 @@ const webpackConfig = merge(baseWebpackConfig, {
31
43
// https://github.com/webpack/webpack/issues/6409
32
44
// https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
33
45
optimization : {
34
- minimize : true ,
35
- runtimeChunk : true ,
46
+ minimizer : [
47
+ // js mini
48
+ new UglifyJsPlugin ( {
49
+ cache : true ,
50
+ parallel : true ,
51
+ sourceMap : config . build . productionSourceMap // set to true if you want JS source maps
52
+ } ) ,
53
+ // css mini
54
+ new OptimizeCSSPlugin ( { } )
55
+ ] ,
36
56
splitChunks : {
37
- // chunks: "async",
38
- // maxAsyncRequests: 5,
39
- // maxInitialRequests: 3,
40
- chunks : 'all' ,
57
+ chunks : 'async' ,
41
58
minSize : 0 ,
42
59
maxAsyncRequests : Infinity ,
43
60
maxInitialRequests : Infinity ,
@@ -50,21 +67,26 @@ const webpackConfig = merge(baseWebpackConfig, {
50
67
priority : - 20 ,
51
68
reuseExistingChunk : true ,
52
69
} ,
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'
70
+ themeDark : {
71
+ name : 'theme-dark' ,
72
+ test : ( m , c , entry = 'theme-dark' ) => recursiveIssuer ( m ) === entry ,
73
+ chunks : 'all' ,
74
+ enforce : true
75
+ } ,
76
+ themeDefault : {
77
+ name : 'theme-default' ,
78
+ test : ( m , c , entry = 'theme-default' ) => recursiveIssuer ( m ) === entry ,
79
+ chunks : 'all' ,
80
+ enforce : true
60
81
} ,
61
82
echarts : {
62
83
name : 'echarts' ,
63
- enforce : true ,
84
+ chunks : 'all' ,
64
85
test : function ( module ) {
65
86
var context = module . context ;
66
87
return context && ( context . indexOf ( 'echarts' ) >= 0 || context . indexOf ( 'zrender' ) >= 0 )
67
- }
88
+ } ,
89
+ enforce : true
68
90
} ,
69
91
vendors : {
70
92
name : 'vendors' ,
@@ -80,26 +102,13 @@ const webpackConfig = merge(baseWebpackConfig, {
80
102
} ,
81
103
chunks : "all"
82
104
}
83
-
84
- // commons: {
85
- // test: /[\\/]node_modules[\\/]/,
86
- // name: "vendors",
87
- // chunks: "all"
88
- // }
89
105
}
90
106
}
91
107
} ,
92
108
plugins : [
93
109
// extract css into its own file
94
- // new ExtractTextPlugin({
95
- // filename: utils.assetsPath('css/[name].[contenthash:7].css')
96
- // }),
97
- // Compress extracted CSS. We are using this plugin so that possible
98
- // duplicated CSS from different components can be deduped.
99
- new OptimizeCSSPlugin ( {
100
- cssProcessorOptions : {
101
- safe : true
102
- }
110
+ new MiniCssExtractPlugin ( {
111
+ filename : utils . assetsPath ( 'css/[name].[contenthash:7].css' )
103
112
} ) ,
104
113
// generate dist index.html with correct asset hash for caching.
105
114
// you can customize output by editing /index.html
@@ -108,48 +117,13 @@ const webpackConfig = merge(baseWebpackConfig, {
108
117
filename : config . build . index ,
109
118
template : './src/index.html' ,
110
119
inject : true ,
111
- // minify: {
112
- // removeComments: true,
113
- // collapseWhitespace: true,
114
- // removeAttributeQuotes: true
115
- // // more options:
116
- // // https://github.com/kangax/html-minifier#options-quick-reference
117
- // },
118
120
minify : false ,
119
121
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
120
122
chunksSortMode : 'dependency' ,
121
123
excludeChunks : [ 'theme-default' , 'theme-dark' ]
122
124
} ) ,
123
125
// keep module.id stable when vender modules does not change
124
126
new webpack . HashedModuleIdsPlugin ( ) ,
125
- // split vendor js into its own file
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
- // }),
139
- // split echarts into its own file
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
- // }),
147
- // extract webpack runtime and module manifest to its own file in order to
148
- // prevent vendor hash from being updated whenever app bundle is updated
149
- // new webpack.optimize.CommonsChunkPlugin({
150
- // name: 'manifest',
151
- // chunks: ['vendor']
152
- // }),
153
127
// copy custom static assets
154
128
new CopyWebpackPlugin ( [
155
129
{
0 commit comments