@@ -42,95 +42,99 @@ module.exports = (api, options) => {
42
42
] )
43
43
44
44
// minify JS
45
+ const UglifyPlugin = require ( 'uglifyjs-webpack-plugin' )
46
+ const uglifyPluginOptions = {
47
+ uglifyOptions : {
48
+ compress : {
49
+ // turn off flags with small gains to speed up minification
50
+ arrows : false ,
51
+ collapse_vars : false , // 0.3kb
52
+ comparisons : false ,
53
+ computed_props : false ,
54
+ hoist_funs : false ,
55
+ hoist_props : false ,
56
+ hoist_vars : false ,
57
+ inline : false ,
58
+ loops : false ,
59
+ negate_iife : false ,
60
+ properties : false ,
61
+ reduce_funcs : false ,
62
+ reduce_vars : false ,
63
+ switches : false ,
64
+ toplevel : false ,
65
+ typeofs : false ,
66
+
67
+ // a few flags with noticable gains/speed ratio
68
+ // numbers based on out of the box vendor bundle
69
+ booleans : true , // 0.7kb
70
+ if_return : true , // 0.4kb
71
+ sequences : true , // 0.7kb
72
+ unused : true , // 2.3kb
73
+
74
+ // required features to drop conditional branches
75
+ conditionals : true ,
76
+ dead_code : true ,
77
+ evaluate : true
78
+ }
79
+ } ,
80
+ sourceMap : options . productionSourceMap ,
81
+ cache : true ,
82
+ parallel : true
83
+ }
45
84
// disable during tests to speed things up
46
85
if ( ! process . env . VUE_CLI_TEST ) {
47
86
webpackConfig
48
- . plugin ( 'uglifyjs' )
49
- . use ( require ( 'uglifyjs-webpack-plugin' ) , [ {
50
- uglifyOptions : {
51
- compress : {
52
- // turn off flags with small gains to speed up minification
53
- arrows : false ,
54
- collapse_vars : false , // 0.3kb
55
- comparisons : false ,
56
- computed_props : false ,
57
- hoist_funs : false ,
58
- hoist_props : false ,
59
- hoist_vars : false ,
60
- inline : false ,
61
- loops : false ,
62
- negate_iife : false ,
63
- properties : false ,
64
- reduce_funcs : false ,
65
- reduce_vars : false ,
66
- switches : false ,
67
- toplevel : false ,
68
- typeofs : false ,
69
-
70
- // a few flags with noticable gains/speed ratio
71
- // numbers based on out of the box vendor bundle
72
- booleans : true , // 0.7kb
73
- if_return : true , // 0.4kb
74
- sequences : true , // 0.7kb
75
- unused : true , // 2.3kb
76
-
77
- // required features to drop conditional branches
78
- conditionals : true ,
79
- dead_code : true ,
80
- evaluate : true
81
- }
82
- } ,
83
- sourceMap : options . productionSourceMap ,
84
- cache : true ,
85
- parallel : true
86
- } ] )
87
+ . plugin ( 'uglify' )
88
+ . use ( UglifyPlugin , [ uglifyPluginOptions ] )
87
89
}
88
90
89
- // Chunk splits
90
91
const CommonsChunkPlugin = require ( 'webpack/lib/optimize/CommonsChunkPlugin' )
91
92
92
- // extract vendor libs into its own chunk for better caching, since they
93
- // are more likely to stay the same.
94
- webpackConfig
95
- . plugin ( 'split-vendor' )
96
- . use ( CommonsChunkPlugin , [ {
97
- name : 'vendor' ,
98
- minChunks ( module ) {
99
- // any required modules inside node_modules are extracted to vendor
100
- return (
101
- module . resource &&
102
- / \. j s $ / . test ( module . resource ) &&
103
- module . resource . indexOf ( `node_modules` ) > - 1
104
- )
105
- }
106
- } ] )
93
+ // Chunk splits
94
+ if ( ! options . dll ) {
95
+ // extract vendor libs into its own chunk for better caching, since they
96
+ // are more likely to stay the same.
97
+ webpackConfig
98
+ . plugin ( 'split-vendor' )
99
+ . use ( CommonsChunkPlugin , [ {
100
+ name : 'vendor' ,
101
+ minChunks ( module ) {
102
+ // any required modules inside node_modules are extracted to vendor
103
+ return (
104
+ module . resource &&
105
+ / \. j s $ / . test ( module . resource ) &&
106
+ module . resource . indexOf ( `node_modules` ) > - 1
107
+ )
108
+ }
109
+ } ] )
107
110
108
- // extract webpack runtime and module manifest to its own file in order to
109
- // prevent vendor hash from being updated whenever app bundle is updated
110
- webpackConfig
111
- . plugin ( 'split-manifest' )
112
- . use ( CommonsChunkPlugin , [ {
113
- name : 'manifest' ,
114
- minChunks : Infinity
115
- } ] )
111
+ // extract webpack runtime and module manifest to its own file in order to
112
+ // prevent vendor hash from being updated whenever app bundle is updated
113
+ webpackConfig
114
+ . plugin ( 'split-manifest' )
115
+ . use ( CommonsChunkPlugin , [ {
116
+ name : 'manifest' ,
117
+ minChunks : Infinity
118
+ } ] )
116
119
117
- // inline the manifest chunk into HTML
118
- webpackConfig
119
- . plugin ( 'inline-manifest' )
120
- . use ( require ( '../webpack/InlineSourcePlugin' ) , [ {
121
- include : / m a n i f e s t \. .* \. j s $ /
122
- } ] )
120
+ // inline the manifest chunk into HTML
121
+ webpackConfig
122
+ . plugin ( 'inline-manifest' )
123
+ . use ( require ( '../webpack/InlineSourcePlugin' ) , [ {
124
+ include : / m a n i f e s t \. .* \. j s $ /
125
+ } ] )
123
126
124
- // since manifest is inlined, don't preload it anymore
125
- webpackConfig
126
- . plugin ( 'preload' )
127
- . tap ( ( [ options ] ) => {
128
- options . fileBlacklist . push ( / m a n i f e s t \. .* \. j s $ / )
129
- return [ options ]
130
- } )
131
-
132
- // This instance extracts shared chunks from code splitted chunks and bundles them
133
- // in a separate chunk, similar to the vendor chunk
127
+ // since manifest is inlined, don't preload it anymore
128
+ webpackConfig
129
+ . plugin ( 'preload' )
130
+ . tap ( ( [ options ] ) => {
131
+ options . fileBlacklist . push ( / m a n i f e s t \. .* \. j s $ / )
132
+ return [ options ]
133
+ } )
134
+ }
135
+
136
+ // This CommonsChunkPlugin instance extracts shared chunks from async
137
+ // chunks and bundles them in a separate chunk, similar to the vendor chunk
134
138
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
135
139
webpackConfig
136
140
. plugin ( 'split-vendor-async' )
@@ -141,6 +145,36 @@ module.exports = (api, options) => {
141
145
minChunks : 3
142
146
} ] )
143
147
148
+ // DLL
149
+ if ( options . dll ) {
150
+ const webpack = require ( 'webpack' )
151
+ const resolveClientEnv = require ( '../util/resolveClientEnv' )
152
+ const dllEntries = Array . isArray ( options . dll )
153
+ ? options . dll
154
+ : Object . keys ( api . service . pkg . dependencies )
155
+
156
+ webpackConfig
157
+ . plugin ( 'dll' )
158
+ . use ( require ( 'autodll-webpack-plugin' ) , [ {
159
+ inject : true ,
160
+ inherit : true ,
161
+ path : 'js/' ,
162
+ context : api . resolve ( '.' ) ,
163
+ filename : '[name].[hash:8].js' ,
164
+ entry : {
165
+ 'vendor' : [
166
+ ...dllEntries ,
167
+ 'vue-loader/lib/component-normalizer'
168
+ ]
169
+ } ,
170
+ plugins : [
171
+ new webpack . DefinePlugin ( resolveClientEnv ( options . baseUrl ) ) ,
172
+ new UglifyPlugin ( uglifyPluginOptions )
173
+ ]
174
+ } ] )
175
+ . after ( 'preload' )
176
+ }
177
+
144
178
// copy static assets in public/
145
179
webpackConfig
146
180
. plugin ( 'copy' )
@@ -162,8 +196,6 @@ module.exports = (api, options) => {
162
196
// .before('vue-loader')
163
197
// .loader('thread-loader')
164
198
// .options({ name: 'vue' })
165
-
166
- // TODO DLL
167
199
}
168
200
} )
169
201
}
0 commit comments