1
1
const path = require ( 'path' ) ;
2
+ const webpack = require ( 'webpack' ) ;
2
3
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
3
4
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
4
5
const ExtractTextPlugin = require ( 'extract-text-webpack-plugin' ) ;
5
6
const autoprefixer = require ( 'autoprefixer' ) ;
6
7
const postcssUrl = require ( 'postcss-url' ) ;
7
8
8
- const { NoEmitOnErrorsPlugin, LoaderOptionsPlugin } = require ( 'webpack' ) ;
9
+ const { NoEmitOnErrorsPlugin, LoaderOptionsPlugin, DefinePlugin , HashedModuleIdsPlugin } = require ( 'webpack' ) ;
9
10
const { GlobCopyWebpackPlugin, BaseHrefWebpackPlugin } = require ( '@angular/cli/plugins/webpack' ) ;
10
- const { CommonsChunkPlugin } = require ( 'webpack' ) . optimize ;
11
+ const { CommonsChunkPlugin, UglifyJsPlugin } = require ( 'webpack' ) . optimize ;
11
12
const { AotPlugin } = require ( '@ngtools/webpack' ) ;
12
13
13
14
const nodeModules = path . join ( process . cwd ( ) , 'node_modules' ) ;
14
15
const entryPoints = [ "inline" , "polyfills" , "sw-register" , "styles" , "vendor" , "main" ] ;
15
16
const baseHref = "" ;
16
17
const deployUrl = "" ;
17
18
19
+ const isProd = ( process . env . NODE_ENV === 'production' ) ;
20
+
21
+ function getPlugins ( ) {
22
+ var plugins = [ ] ;
23
+
24
+ // Always expose NODE_ENV to webpack, you can now use `process.env.NODE_ENV`
25
+ // inside your code for any environment checks; UglifyJS will automatically
26
+ // drop any unreachable code.
27
+ plugins . push ( new DefinePlugin ( {
28
+ "process.env.NODE_ENV" : "\"production\""
29
+ } ) ) ;
30
+
31
+ plugins . push ( new NoEmitOnErrorsPlugin ( ) ) ;
32
+
33
+ plugins . push ( new GlobCopyWebpackPlugin ( {
34
+ "patterns" : [
35
+ "assets" ,
36
+ "favicon.ico"
37
+ ] ,
38
+ "globOptions" : {
39
+ "cwd" : "C:\\_PROJECTS\\_PERSO\\angular-electron\\src" ,
40
+ "dot" : true ,
41
+ "ignore" : "**/.gitkeep"
42
+ }
43
+ } ) ) ;
44
+
45
+ plugins . push ( new ProgressPlugin ( ) ) ;
46
+
47
+ plugins . push ( new HtmlWebpackPlugin ( {
48
+ "template" : "./src/index.html" ,
49
+ "filename" : "./index.html" ,
50
+ "hash" : false ,
51
+ "inject" : true ,
52
+ "compile" : true ,
53
+ "favicon" : false ,
54
+ "minify" : false ,
55
+ "cache" : true ,
56
+ "showErrors" : true ,
57
+ "chunks" : "all" ,
58
+ "excludeChunks" : [ ] ,
59
+ "title" : "Webpack App" ,
60
+ "xhtml" : true ,
61
+ "chunksSortMode" : function sort ( left , right ) {
62
+ let leftIndex = entryPoints . indexOf ( left . names [ 0 ] ) ;
63
+ let rightindex = entryPoints . indexOf ( right . names [ 0 ] ) ;
64
+ if ( leftIndex > rightindex ) {
65
+ return 1 ;
66
+ }
67
+ else if ( leftIndex < rightindex ) {
68
+ return - 1 ;
69
+ }
70
+ else {
71
+ return 0 ;
72
+ }
73
+ }
74
+ } ) ) ;
75
+
76
+ plugins . push ( new BaseHrefWebpackPlugin ( { } ) ) ;
77
+
78
+ plugins . push ( new CommonsChunkPlugin ( {
79
+ "name" : "inline" ,
80
+ "minChunks" : null
81
+ } ) ) ;
82
+
83
+ plugins . push ( new CommonsChunkPlugin ( {
84
+ "name" : "vendor" ,
85
+ "minChunks" : ( module ) => module . resource && module . resource . startsWith ( nodeModules ) ,
86
+ "chunks" : [
87
+ "main"
88
+ ]
89
+ } ) ) ;
90
+
91
+ plugins . push ( new ExtractTextPlugin ( {
92
+ "filename" : "[name].bundle.css" ,
93
+ "disable" : true
94
+ } ) ) ;
95
+
96
+ plugins . push ( new LoaderOptionsPlugin ( {
97
+ "sourceMap" : false ,
98
+ "options" : {
99
+ "postcss" : [
100
+ autoprefixer ( ) ,
101
+ postcssUrl ( { "url" : ( obj ) => {
102
+ // Only convert root relative URLs, which CSS-Loader won't process into require().
103
+ if ( ! obj . url . startsWith ( '/' ) || obj . url . startsWith ( '//' ) ) {
104
+ return obj . url ;
105
+ }
106
+ if ( deployUrl . match ( / : \/ \/ / ) ) {
107
+ // If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
108
+ return `${ deployUrl . replace ( / \/ $ / , '' ) } ${ obj . url } ` ;
109
+ }
110
+ else if ( baseHref . match ( / : \/ \/ / ) ) {
111
+ // If baseHref contains a scheme, include it as is.
112
+ return baseHref . replace ( / \/ $ / , '' ) +
113
+ `/${ deployUrl } /${ obj . url } ` . replace ( / \/ \/ + / g, '/' ) ;
114
+ }
115
+ else {
116
+ // Join together base-href, deploy-url and the original URL.
117
+ // Also dedupe multiple slashes into single ones.
118
+ return `/${ baseHref } /${ deployUrl } /${ obj . url } ` . replace ( / \/ \/ + / g, '/' ) ;
119
+ }
120
+ } } )
121
+ ] ,
122
+ "sassLoader" : {
123
+ "sourceMap" : false ,
124
+ "includePaths" : [ ]
125
+ } ,
126
+ "lessLoader" : {
127
+ "sourceMap" : false
128
+ } ,
129
+ "context" : ""
130
+ }
131
+ } ) ) ;
132
+
133
+ if ( isProd ) {
134
+ plugins . push ( new HashedModuleIdsPlugin ( {
135
+ "hashFunction" : "md5" ,
136
+ "hashDigest" : "base64" ,
137
+ "hashDigestLength" : 4
138
+ } ) ) ;
139
+
140
+ plugins . push ( new AotPlugin ( {
141
+ "mainPath" : "main.ts" ,
142
+ "hostReplacementPaths" : {
143
+ "environments/index.ts" : "environments/index.prod.ts"
144
+ } ,
145
+ "exclude" : [ ] ,
146
+ "tsConfigPath" : "src/tsconfig.app.json"
147
+ } ) ) ;
148
+
149
+ plugins . push ( new UglifyJsPlugin ( {
150
+ "mangle" : {
151
+ "screw_ie8" : true
152
+ } ,
153
+ "compress" : {
154
+ "screw_ie8" : true ,
155
+ "warnings" : false
156
+ } ,
157
+ "sourceMap" : false
158
+ } ) ) ;
159
+
160
+ } else {
161
+ plugins . push ( new AotPlugin ( {
162
+ "mainPath" : "main.ts" ,
163
+ "hostReplacementPaths" : {
164
+ "environments/index.ts" : "environments/index.ts"
165
+ } ,
166
+ "exclude" : [ ] ,
167
+ "tsConfigPath" : "src/tsconfig.app.json" ,
168
+ "skipCodeGeneration" : true
169
+ } ) ) ;
170
+ }
171
+
172
+ return plugins ;
173
+ }
174
+
18
175
module . exports = {
19
176
"devtool" : "source-map" ,
20
177
"externals" : {
@@ -24,8 +181,13 @@ module.exports = {
24
181
"resolve" : {
25
182
"extensions" : [
26
183
".ts" ,
27
- ".js"
184
+ ".js" ,
185
+ ".scss"
28
186
] ,
187
+ "aliasFields" : [ ] ,
188
+ "alias" : { // WORKAROUND See. angular-cli/issues/5433
189
+ "environments" : isProd ? path . resolve ( __dirname , 'src/environments/index.prod.ts' ) : path . resolve ( __dirname , 'src/environments/index.ts' )
190
+ } ,
29
191
"modules" : [
30
192
"./node_modules"
31
193
]
@@ -189,110 +351,7 @@ module.exports = {
189
351
}
190
352
]
191
353
} ,
192
- "plugins" : [
193
- new NoEmitOnErrorsPlugin ( ) ,
194
- new GlobCopyWebpackPlugin ( {
195
- "patterns" : [
196
- "assets" ,
197
- "favicon.ico"
198
- ] ,
199
- "globOptions" : {
200
- "cwd" : "C:\\_PROJECTS\\_PERSO\\angular-electron\\src" ,
201
- "dot" : true ,
202
- "ignore" : "**/.gitkeep"
203
- }
204
- } ) ,
205
- new ProgressPlugin ( ) ,
206
- new HtmlWebpackPlugin ( {
207
- "template" : "./src/index.html" ,
208
- "filename" : "./index.html" ,
209
- "hash" : false ,
210
- "inject" : true ,
211
- "compile" : true ,
212
- "favicon" : false ,
213
- "minify" : false ,
214
- "cache" : true ,
215
- "showErrors" : true ,
216
- "chunks" : "all" ,
217
- "excludeChunks" : [ ] ,
218
- "title" : "Webpack App" ,
219
- "xhtml" : true ,
220
- "chunksSortMode" : function sort ( left , right ) {
221
- let leftIndex = entryPoints . indexOf ( left . names [ 0 ] ) ;
222
- let rightindex = entryPoints . indexOf ( right . names [ 0 ] ) ;
223
- if ( leftIndex > rightindex ) {
224
- return 1 ;
225
- }
226
- else if ( leftIndex < rightindex ) {
227
- return - 1 ;
228
- }
229
- else {
230
- return 0 ;
231
- }
232
- }
233
- } ) ,
234
- new BaseHrefWebpackPlugin ( { } ) ,
235
- new CommonsChunkPlugin ( {
236
- "name" : "inline" ,
237
- "minChunks" : null
238
- } ) ,
239
- new CommonsChunkPlugin ( {
240
- "name" : "vendor" ,
241
- "minChunks" : ( module ) => module . resource && module . resource . startsWith ( nodeModules ) ,
242
- "chunks" : [
243
- "main"
244
- ]
245
- } ) ,
246
- new ExtractTextPlugin ( {
247
- "filename" : "[name].bundle.css" ,
248
- "disable" : true
249
- } ) ,
250
- new LoaderOptionsPlugin ( {
251
- "sourceMap" : false ,
252
- "options" : {
253
- "postcss" : [
254
- autoprefixer ( ) ,
255
- postcssUrl ( { "url" : ( obj ) => {
256
- // Only convert root relative URLs, which CSS-Loader won't process into require().
257
- if ( ! obj . url . startsWith ( '/' ) || obj . url . startsWith ( '//' ) ) {
258
- return obj . url ;
259
- }
260
- if ( deployUrl . match ( / : \/ \/ / ) ) {
261
- // If deployUrl contains a scheme, ignore baseHref use deployUrl as is.
262
- return `${ deployUrl . replace ( / \/ $ / , '' ) } ${ obj . url } ` ;
263
- }
264
- else if ( baseHref . match ( / : \/ \/ / ) ) {
265
- // If baseHref contains a scheme, include it as is.
266
- return baseHref . replace ( / \/ $ / , '' ) +
267
- `/${ deployUrl } /${ obj . url } ` . replace ( / \/ \/ + / g, '/' ) ;
268
- }
269
- else {
270
- // Join together base-href, deploy-url and the original URL.
271
- // Also dedupe multiple slashes into single ones.
272
- return `/${ baseHref } /${ deployUrl } /${ obj . url } ` . replace ( / \/ \/ + / g, '/' ) ;
273
- }
274
- } } )
275
- ] ,
276
- "sassLoader" : {
277
- "sourceMap" : false ,
278
- "includePaths" : [ ]
279
- } ,
280
- "lessLoader" : {
281
- "sourceMap" : false
282
- } ,
283
- "context" : ""
284
- }
285
- } ) ,
286
- new AotPlugin ( {
287
- "mainPath" : "main.ts" ,
288
- "hostReplacementPaths" : {
289
- "environments/environment.ts" : "environments/environment.ts"
290
- } ,
291
- "exclude" : [ ] ,
292
- "tsConfigPath" : "src/tsconfig.app.json" ,
293
- "skipCodeGeneration" : true
294
- } )
295
- ] ,
354
+ "plugins" : getPlugins ( ) ,
296
355
"node" : {
297
356
"fs" : "empty" ,
298
357
"global" : true ,
0 commit comments