5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- // tslint:disable
9
- // TODO: cleanup this file, it's copied as is from Angular CLI.
10
-
8
+ import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
11
9
import * as path from 'path' ;
12
10
import { HashedModuleIdsPlugin , debug } from 'webpack' ;
13
- import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
14
- import { getOutputHashFormat } from './utils' ;
15
- import { isDirectory } from '../../utilities/is-directory' ;
16
- import { requireProjectModule } from '../../utilities/require-project-module' ;
17
- import { WebpackConfigOptions } from '../build-options' ;
11
+ import { AssetPatternObject } from '../../../browser/schema' ;
18
12
import { BundleBudgetPlugin } from '../../plugins/bundle-budget' ;
19
13
import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin' ;
20
14
import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin' ;
21
15
import { findUp } from '../../utilities/find-up' ;
22
- import { AssetPatternObject } from '../../../browser/schema' ;
23
- import { normalizeExtraEntryPoints } from './utils' ;
16
+ import { isDirectory } from '../../utilities/is-directory' ;
17
+ import { requireProjectModule } from '../../utilities/require-project-module' ;
18
+ import { WebpackConfigOptions } from '../build-options' ;
19
+ import { getOutputHashFormat , normalizeExtraEntryPoints } from './utils' ;
24
20
25
21
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
26
22
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
27
23
const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
28
24
const StatsPlugin = require ( 'stats-webpack-plugin' ) ;
29
25
30
- /**
31
- * Enumerate loaders and their dependencies from this file to let the dependency validator
32
- * know they are used.
33
- *
34
- * require('source-map-loader')
35
- * require('raw-loader')
36
- * require('url-loader')
37
- * require('file-loader')
38
- * require('@angular-devkit/build-optimizer')
39
- */
40
26
27
+ // tslint:disable-next-line:no-any
41
28
const g : any = typeof global !== 'undefined' ? global : { } ;
42
29
export const buildOptimizerLoader : string = g [ '_DevKitIsLocal' ]
43
30
? require . resolve ( '@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader' )
44
31
: '@angular-devkit/build-optimizer/webpack-loader' ;
45
32
33
+ // tslint:disable-next-line:no-big-function
46
34
export function getCommonConfig ( wco : WebpackConfigOptions ) {
47
35
const { root, projectRoot, buildOptions } = wco ;
48
36
49
37
const nodeModules = findUp ( 'node_modules' , projectRoot ) ;
50
38
if ( ! nodeModules ) {
51
- throw new Error ( 'Cannot locate node_modules directory.' )
39
+ throw new Error ( 'Cannot locate node_modules directory.' ) ;
52
40
}
53
41
54
- let extraPlugins : any [ ] = [ ] ;
55
- let entryPoints : { [ key : string ] : string [ ] } = { } ;
42
+ // tslint:disable-next-line:no-any
43
+ const extraPlugins : any [ ] = [ ] ;
44
+ const entryPoints : { [ key : string ] : string [ ] } = { } ;
56
45
57
46
if ( buildOptions . main ) {
58
47
entryPoints [ 'main' ] = [ path . resolve ( root , buildOptions . main ) ] ;
@@ -72,19 +61,19 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
72
61
if ( buildOptions . profile ) {
73
62
extraPlugins . push ( new debug . ProfilingPlugin ( {
74
63
outputPath : path . resolve ( root , 'chrome-profiler-events.json' ) ,
75
- } ) )
64
+ } ) ) ;
76
65
}
77
66
78
67
// determine hashing format
79
- const hashFormat = getOutputHashFormat ( buildOptions . outputHashing as any ) ;
68
+ const hashFormat = getOutputHashFormat ( buildOptions . outputHashing || 'none' ) ;
80
69
81
70
// process global scripts
82
71
if ( buildOptions . scripts . length > 0 ) {
83
72
const globalScriptsByBundleName = normalizeExtraEntryPoints ( buildOptions . scripts , 'scripts' )
84
73
. reduce ( ( prev : { bundleName : string , paths : string [ ] , lazy : boolean } [ ] , curr ) => {
85
74
const bundleName = curr . bundleName ;
86
75
const resolvedPath = path . resolve ( root , curr . input ) ;
87
- let existingEntry = prev . find ( ( el ) => el . bundleName === bundleName ) ;
76
+ const existingEntry = prev . find ( ( el ) => el . bundleName === bundleName ) ;
88
77
if ( existingEntry ) {
89
78
if ( existingEntry . lazy && ! curr . lazy ) {
90
79
// All entries have to be lazy for the bundle to be lazy.
@@ -97,9 +86,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
97
86
prev . push ( {
98
87
bundleName,
99
88
paths : [ resolvedPath ] ,
100
- lazy : curr . lazy
89
+ lazy : curr . lazy ,
101
90
} ) ;
102
91
}
92
+
103
93
return prev ;
104
94
} , [ ] ) ;
105
95
@@ -141,8 +131,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
141
131
ignore : asset . ignore ,
142
132
from : {
143
133
glob : asset . glob ,
144
- dot : true
145
- }
134
+ dot : true ,
135
+ } ,
146
136
} ;
147
137
} ) ;
148
138
@@ -159,7 +149,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
159
149
160
150
if ( buildOptions . showCircularDependencies ) {
161
151
extraPlugins . push ( new CircularDependencyPlugin ( {
162
- exclude : / [ \\ \/ ] n o d e _ m o d u l e s [ \\ \/ ] /
152
+ exclude : / [ \\ \/ ] n o d e _ m o d u l e s [ \\ \/ ] / ,
163
153
} ) ) ;
164
154
}
165
155
@@ -172,10 +162,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
172
162
sourceMapUseRule = {
173
163
use : [
174
164
{
175
- loader : 'source-map-loader'
176
- }
177
- ]
178
- }
165
+ loader : 'source-map-loader' ,
166
+ } ,
167
+ ] ,
168
+ } ;
179
169
}
180
170
181
171
let buildOptimizerUseRule ;
@@ -184,7 +174,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
184
174
use : [
185
175
{
186
176
loader : buildOptimizerLoader ,
187
- options : { sourceMap : buildOptions . sourceMap }
177
+ options : { sourceMap : buildOptions . sourceMap } ,
188
178
} ,
189
179
] ,
190
180
} ;
@@ -253,10 +243,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
253
243
wco . tsConfig . options . baseUrl || projectRoot ,
254
244
'node_modules' ,
255
245
] ,
256
- alias
246
+ alias,
257
247
} ,
258
248
resolveLoader : {
259
- modules : loaderNodeModules
249
+ modules : loaderNodeModules ,
260
250
} ,
261
251
context : projectRoot ,
262
252
entry : entryPoints ,
@@ -267,7 +257,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
267
257
} ,
268
258
watch : buildOptions . watch ,
269
259
watchOptions : {
270
- poll : buildOptions . poll
260
+ poll : buildOptions . poll ,
271
261
} ,
272
262
performance : {
273
263
hints : false ,
@@ -280,7 +270,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
280
270
loader : 'file-loader' ,
281
271
options : {
282
272
name : `[name]${ hashFormat . file } .[ext]` ,
283
- }
273
+ } ,
284
274
} ,
285
275
{
286
276
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
@@ -298,7 +288,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
298
288
enforce : 'pre' ,
299
289
...sourceMapUseRule ,
300
290
} ,
301
- ]
291
+ ] ,
302
292
} ,
303
293
optimization : {
304
294
noEmitOnErrors : true ,
0 commit comments