@@ -13,7 +13,7 @@ import {
13
13
resolve ,
14
14
} from '@angular-devkit/core' ;
15
15
import * as path from 'path' ;
16
- import * as webpack from 'webpack' ;
16
+ import { Configuration , JavascriptModulesPlugin } from 'webpack' ;
17
17
import { merge as webpackMerge } from 'webpack-merge' ;
18
18
import { Schema as BrowserBuilderSchema } from '../browser/schema' ;
19
19
import {
@@ -33,10 +33,10 @@ export async function generateWebpackConfig(
33
33
projectRoot : string ,
34
34
sourceRoot : string | undefined ,
35
35
options : NormalizedBrowserBuilderSchema ,
36
- webpackPartialGenerator : ( wco : BrowserWebpackConfigOptions ) => webpack . Configuration [ ] ,
36
+ webpackPartialGenerator : ( wco : BrowserWebpackConfigOptions ) => Configuration [ ] ,
37
37
logger : logging . LoggerApi ,
38
38
extraBuildOptions : Partial < NormalizedBrowserBuilderSchema > ,
39
- ) : Promise < webpack . Configuration > {
39
+ ) : Promise < Configuration > {
40
40
// Ensure Build Optimizer is only used with AOT.
41
41
if ( options . buildOptimizer && ! options . aot ) {
42
42
throw new Error ( `The 'buildOptimizer' option cannot be used without 'aot'.` ) ;
@@ -70,9 +70,9 @@ export async function generateWebpackConfig(
70
70
export async function generateI18nBrowserWebpackConfigFromContext (
71
71
options : BrowserBuilderSchema ,
72
72
context : BuilderContext ,
73
- webpackPartialGenerator : ( wco : BrowserWebpackConfigOptions ) => webpack . Configuration [ ] ,
73
+ webpackPartialGenerator : ( wco : BrowserWebpackConfigOptions ) => Configuration [ ] ,
74
74
extraBuildOptions : Partial < NormalizedBrowserBuilderSchema > = { } ,
75
- ) : Promise < { config : webpack . Configuration ; projectRoot : string ; projectSourceRoot ?: string , i18n : I18nOptions } > {
75
+ ) : Promise < { config : Configuration ; projectRoot : string ; projectSourceRoot ?: string , i18n : I18nOptions } > {
76
76
const { buildOptions, i18n } = await configureI18nBuild ( context , options ) ;
77
77
const result = await generateBrowserWebpackConfigFromContext (
78
78
buildOptions ,
@@ -106,25 +106,14 @@ export async function generateI18nBrowserWebpackConfigFromContext(
106
106
( data , locale ) => data + locale . files . map ( ( file ) => file . integrity || '' ) . join ( '|' ) ,
107
107
'' ,
108
108
) ;
109
- if ( ! config . plugins ) {
110
- config . plugins = [ ] ;
111
- }
109
+
110
+ config . plugins ??= [ ] ;
112
111
config . plugins . push ( {
113
- apply ( compiler : webpack . Compiler ) {
112
+ apply ( compiler ) {
114
113
compiler . hooks . compilation . tap ( 'build-angular' , compilation => {
115
- // Webpack typings do not contain template hashForChunk hook
116
- // tslint:disable-next-line: no-any
117
- ( compilation . mainTemplate . hooks as any ) . hashForChunk . tap (
118
- 'build-angular' ,
119
- ( hash : { update ( data : string ) : void } ) => {
120
- hash . update ( '$localize' + i18nHash ) ;
121
- } ,
122
- ) ;
123
- // Webpack typings do not contain hooks property
124
- // tslint:disable-next-line: no-any
125
- ( compilation . chunkTemplate as any ) . hooks . hashForChunk . tap (
114
+ JavascriptModulesPlugin . getCompilationHooks ( compilation ) . chunkHash . tap (
126
115
'build-angular' ,
127
- ( hash : { update ( data : string ) : void } ) => {
116
+ ( _ , hash ) => {
128
117
hash . update ( '$localize' + i18nHash ) ;
129
118
} ,
130
119
) ;
@@ -138,9 +127,9 @@ export async function generateI18nBrowserWebpackConfigFromContext(
138
127
export async function generateBrowserWebpackConfigFromContext (
139
128
options : BrowserBuilderSchema ,
140
129
context : BuilderContext ,
141
- webpackPartialGenerator : ( wco : BrowserWebpackConfigOptions ) => webpack . Configuration [ ] ,
130
+ webpackPartialGenerator : ( wco : BrowserWebpackConfigOptions ) => Configuration [ ] ,
142
131
extraBuildOptions : Partial < NormalizedBrowserBuilderSchema > = { } ,
143
- ) : Promise < { config : webpack . Configuration ; projectRoot : string ; projectSourceRoot ?: string } > {
132
+ ) : Promise < { config : Configuration ; projectRoot : string ; projectSourceRoot ?: string } > {
144
133
const projectName = context . target && context . target . project ;
145
134
if ( ! projectName ) {
146
135
throw new Error ( 'The builder requires a target.' ) ;
0 commit comments