55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
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' ;
119import * as path from 'path' ;
1210import { 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' ;
1812import { BundleBudgetPlugin } from '../../plugins/bundle-budget' ;
1913import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin' ;
2014import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin' ;
2115import { 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' ;
2420
2521const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
2622const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
2723const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
2824const StatsPlugin = require ( 'stats-webpack-plugin' ) ;
2925
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- */
4026
27+ // tslint:disable-next-line:no-any
4128const g : any = typeof global !== 'undefined' ? global : { } ;
4229export const buildOptimizerLoader : string = g [ '_DevKitIsLocal' ]
4330 ? require . resolve ( '@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader' )
4431 : '@angular-devkit/build-optimizer/webpack-loader' ;
4532
33+ // tslint:disable-next-line:no-big-function
4634export function getCommonConfig ( wco : WebpackConfigOptions ) {
4735 const { root, projectRoot, buildOptions } = wco ;
4836
4937 const nodeModules = findUp ( 'node_modules' , projectRoot ) ;
5038 if ( ! nodeModules ) {
51- throw new Error ( 'Cannot locate node_modules directory.' )
39+ throw new Error ( 'Cannot locate node_modules directory.' ) ;
5240 }
5341
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 [ ] } = { } ;
5645
5746 if ( buildOptions . main ) {
5847 entryPoints [ 'main' ] = [ path . resolve ( root , buildOptions . main ) ] ;
@@ -72,19 +61,19 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
7261 if ( buildOptions . profile ) {
7362 extraPlugins . push ( new debug . ProfilingPlugin ( {
7463 outputPath : path . resolve ( root , 'chrome-profiler-events.json' ) ,
75- } ) )
64+ } ) ) ;
7665 }
7766
7867 // determine hashing format
79- const hashFormat = getOutputHashFormat ( buildOptions . outputHashing as any ) ;
68+ const hashFormat = getOutputHashFormat ( buildOptions . outputHashing || 'none' ) ;
8069
8170 // process global scripts
8271 if ( buildOptions . scripts . length > 0 ) {
8372 const globalScriptsByBundleName = normalizeExtraEntryPoints ( buildOptions . scripts , 'scripts' )
8473 . reduce ( ( prev : { bundleName : string , paths : string [ ] , lazy : boolean } [ ] , curr ) => {
8574 const bundleName = curr . bundleName ;
8675 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 ) ;
8877 if ( existingEntry ) {
8978 if ( existingEntry . lazy && ! curr . lazy ) {
9079 // All entries have to be lazy for the bundle to be lazy.
@@ -97,9 +86,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
9786 prev . push ( {
9887 bundleName,
9988 paths : [ resolvedPath ] ,
100- lazy : curr . lazy
89+ lazy : curr . lazy ,
10190 } ) ;
10291 }
92+
10393 return prev ;
10494 } , [ ] ) ;
10595
@@ -141,8 +131,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
141131 ignore : asset . ignore ,
142132 from : {
143133 glob : asset . glob ,
144- dot : true
145- }
134+ dot : true ,
135+ } ,
146136 } ;
147137 } ) ;
148138
@@ -159,7 +149,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
159149
160150 if ( buildOptions . showCircularDependencies ) {
161151 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 [ \\ \/ ] / ,
163153 } ) ) ;
164154 }
165155
@@ -172,10 +162,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
172162 sourceMapUseRule = {
173163 use : [
174164 {
175- loader : 'source-map-loader'
176- }
177- ]
178- }
165+ loader : 'source-map-loader' ,
166+ } ,
167+ ] ,
168+ } ;
179169 }
180170
181171 let buildOptimizerUseRule ;
@@ -184,7 +174,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
184174 use : [
185175 {
186176 loader : buildOptimizerLoader ,
187- options : { sourceMap : buildOptions . sourceMap }
177+ options : { sourceMap : buildOptions . sourceMap } ,
188178 } ,
189179 ] ,
190180 } ;
@@ -253,10 +243,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
253243 wco . tsConfig . options . baseUrl || projectRoot ,
254244 'node_modules' ,
255245 ] ,
256- alias
246+ alias,
257247 } ,
258248 resolveLoader : {
259- modules : loaderNodeModules
249+ modules : loaderNodeModules ,
260250 } ,
261251 context : projectRoot ,
262252 entry : entryPoints ,
@@ -267,7 +257,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
267257 } ,
268258 watch : buildOptions . watch ,
269259 watchOptions : {
270- poll : buildOptions . poll
260+ poll : buildOptions . poll ,
271261 } ,
272262 performance : {
273263 hints : false ,
@@ -280,7 +270,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
280270 loader : 'file-loader' ,
281271 options : {
282272 name : `[name]${ hashFormat . file } .[ext]` ,
283- }
273+ } ,
284274 } ,
285275 {
286276 // Mark files inside `@angular/core` as using SystemJS style dynamic imports.
@@ -298,7 +288,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
298288 enforce : 'pre' ,
299289 ...sourceMapUseRule ,
300290 } ,
301- ]
291+ ] ,
302292 } ,
303293 optimization : {
304294 noEmitOnErrors : true ,
0 commit comments