@@ -10,16 +10,17 @@ const autoprefixer = require('autoprefixer');
10
10
const cssnano = require ( 'cssnano' ) ;
11
11
const CopyWebpackPlugin = require ( 'copy-webpack-plugin' ) ;
12
12
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
13
- const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
13
+ const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
14
14
const AotPlugin = require ( '@ngtools/webpack' ) . AngularCompilerPlugin ;
15
15
const NormalModuleReplacementPlugin = webpack . NormalModuleReplacementPlugin ;
16
+ const DefinePlugin = webpack . DefinePlugin ;
16
17
const bundles = [ / ^ p o l y f i l l s / i, / ^ c o m m o n s ( ~ ) ? / i, / ^ v e n d o r s ~ / i, / ^ a p p / i, / ^ s t y l e s / i, / .* / ] ;
17
18
18
19
const config = {
19
20
mode : 'none' ,
20
21
entry : {
21
- app : path . join ( __dirname , './src/client/main.ts' ) ,
22
- polyfills : path . join ( __dirname , './src/client/polyfills.ts' ) ,
22
+ app : path . join ( __dirname , './src/client/main.ts' ) ,
23
+ polyfills : path . join ( __dirname , './src/client/polyfills.ts' ) ,
23
24
styles : path . join ( __dirname , './src/client/scss/styles.scss' )
24
25
} ,
25
26
output : {
@@ -29,7 +30,7 @@ const config = {
29
30
} ,
30
31
resolve : {
31
32
extensions : [ '.ts' , '.js' , '.json' , '.scss' , '.css' ] ,
32
- mainFields : [ 'module' ] ,
33
+ mainFields : [ 'module' , 'browser' , 'main' ] ,
33
34
alias : {
34
35
'/assets' : path . join ( __dirname , './src/client/assets' )
35
36
}
@@ -50,29 +51,22 @@ const config = {
50
51
{
51
52
loader : 'css-loader' ,
52
53
options : {
53
- // url: false
54
- }
55
- } ,
56
- {
57
- loader :'resolve-url-loader' ,
58
- options : {
59
- root : path . join ( __dirname , './src/client' ) ,
60
- debug : true
54
+ esModule : false
61
55
}
62
56
} ,
63
57
{
64
58
loader : 'postcss-loader' ,
65
59
options : {
66
60
postcssOptions : {
67
61
plugins : [
68
- autoprefixer ( { remove : false , flexbox : true } ) ,
69
- cssnano ( { zindex : false } )
62
+ autoprefixer ( { remove : false , flexbox : true } ) ,
63
+ cssnano ( { zindex : false } )
70
64
]
71
65
}
72
66
}
73
67
} ,
74
68
{
75
- loader :'sass-loader' ,
69
+ loader : 'sass-loader' ,
76
70
options : {
77
71
sassOptions : {
78
72
includePaths : [ path . join ( __dirname , './src/client/scss' ) ]
@@ -102,20 +96,14 @@ const config = {
102
96
options : {
103
97
postcssOptions : {
104
98
plugins : [
105
- autoprefixer ( { remove : false , flexbox : true } ) ,
106
- cssnano ( { zindex : false } )
99
+ autoprefixer ( { remove : false , flexbox : true } ) ,
100
+ cssnano ( { zindex : false } )
107
101
] ,
108
102
}
109
103
}
110
104
} ,
111
105
{
112
- loader :'resolve-url-loader' ,
113
- options : {
114
- root : path . join ( __dirname , './src/client' )
115
- }
116
- } ,
117
- {
118
- loader :'sass-loader' ,
106
+ loader : 'sass-loader' ,
119
107
options : {
120
108
sassOptions : {
121
109
includePaths : [ path . join ( __dirname , './src/client/scss' ) ]
@@ -136,19 +124,19 @@ const config = {
136
124
} ,
137
125
{
138
126
test : / f o n t ( s ) ? \. s v g / ,
139
- exclude : / \. s v g \. j s / ,
127
+ exclude : / \. s v g \. j s / ,
140
128
use : [
141
129
{
142
130
loader : 'url-loader' ,
143
131
options : {
144
- limit : 10 * 1024 ,
132
+ limit : 10 * 1024 ,
145
133
name : 'fonts/[name].svg'
146
134
}
147
135
}
148
136
]
149
137
} ,
150
- // images
151
- {
138
+ // images
139
+ {
152
140
test : / a s s e t s \/ .* ?\. ( ( j p g ) | ( p n g ) | ( g i f ) | ( b m p ) | ( w e b p ) | ( s v g ) ) / ,
153
141
loader : 'url-loader' ,
154
142
// exclude: [path.join(__dirname, './src/client/assets')],
@@ -160,19 +148,26 @@ const config = {
160
148
// templateUrl
161
149
{
162
150
test : / \. h t m l $ / ,
163
- use : 'html-loader'
151
+ use : [
152
+ {
153
+ loader : 'html-loader' ,
154
+ options : {
155
+ minimize : true
156
+ }
157
+ }
158
+ ]
164
159
}
165
160
]
166
161
} ,
167
162
optimization : {
168
163
// runtimeChunk: 'single',
169
164
flagIncludedChunks : true ,
170
- occurrenceOrder : true ,
171
165
sideEffects : true ,
172
166
usedExports : true ,
173
167
concatenateModules : true ,
174
168
providedExports : true ,
175
169
splitChunks : {
170
+ chunks : 'async' ,
176
171
hidePathInfo : true ,
177
172
minSize : 30000 ,
178
173
maxSize : 977000 , // try and stay below recomended size
@@ -184,22 +179,21 @@ const config = {
184
179
vendors : {
185
180
test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
186
181
priority : - 10 ,
182
+ reuseExistingChunk : true ,
187
183
} ,
188
184
default : {
189
185
name : 'commons' ,
190
186
minChunks : 2 ,
191
187
reuseExistingChunk : true ,
192
188
priority : - 20
193
189
}
194
- }
190
+ }
195
191
} ,
196
192
minimize : true ,
197
193
} ,
198
194
plugins : [
199
195
new TerserPlugin ( {
200
196
parallel : true ,
201
- sourceMap : process . env . BUILD_MODE === 'development' ,
202
- cache : true ,
203
197
terserOptions : {
204
198
compress : true ,
205
199
output : {
@@ -214,19 +208,19 @@ const config = {
214
208
hash : false ,
215
209
showErrors : false ,
216
210
excludeAssets : [ / s t y l e s \. .* j s / i] ,
217
- chunksSortMode : ( a , b ) => {
211
+ chunksSortMode : ( a , b ) => {
218
212
return bundles . findIndex ( pattern => pattern . test ( a ) ) - bundles . findIndex ( pattern => pattern . test ( b ) ) ;
219
213
} ,
220
214
} ) ,
221
215
new HtmlWebpackSkipAssetsPlugin ( ) ,
222
216
new HtmlWebpackLinkTypePlugin ( ) ,
223
- new NoModulePlugin ( { filePatterns : [ 'polyfills.**.js' ] } ) ,
217
+ new NoModulePlugin ( { filePatterns : [ 'polyfills.**.js' ] } ) ,
224
218
new AotPlugin ( {
225
219
tsConfigPath : path . join ( __dirname , './src/client/tsconfig.app.json' ) ,
226
220
mainPath : path . join ( __dirname , './src/client/main.ts' ) ,
227
221
typeChecking : false ,
228
222
} ) ,
229
- new MiniCssExtractPlugin ( {
223
+ new MiniCssExtractPlugin ( {
230
224
filename : '[name].[contenthash].min.css'
231
225
} ) ,
232
226
new CircularDependencyPlugin ( {
@@ -253,13 +247,18 @@ const config = {
253
247
}
254
248
]
255
249
} ) ,
256
- new NormalModuleReplacementPlugin ( / e n v i r o n m e n t s \/ e n v i r o n m e n t / , function ( resource ) {
257
- resource . request = resource . request . replace ( / e n v i r o n m e n t $ / , ( process . env . BUILD_MODE === 'development' ? 'devEnvironment' :'prodEnvironment' ) ) ;
250
+ new NormalModuleReplacementPlugin ( / e n v i r o n m e n t s \/ e n v i r o n m e n t / , function ( resource ) {
251
+ resource . request = resource . request . replace ( / e n v i r o n m e n t $ / , ( process . env . BUILD_MODE === 'development' ? 'devEnvironment' : 'prodEnvironment' ) ) ;
252
+ } ) ,
253
+ new DefinePlugin ( {
254
+ 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV ) ,
255
+ 'process.env.NODE_DEBUG' : JSON . stringify ( process . env . NODE_DEBUG ) ,
256
+ 'process.type' : JSON . stringify ( process . type ) ,
257
+ 'process.version' : JSON . stringify ( process . version ) ,
258
258
} ) ,
259
259
new workbox . InjectManifest ( {
260
260
swSrc : path . join ( __dirname , './src/client/sw.js' ) ,
261
261
swDest : 'sw.js' ,
262
- // importsDirectory: 'wb-assets',
263
262
264
263
exclude : [
265
264
/ s t y l e s \. .* \. m i n \. j s / i, // empty bundle file from extractText
0 commit comments