@@ -11,6 +11,8 @@ import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin';
11
11
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
12
12
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
13
13
const SilentError = require ( 'silent-error' ) ;
14
+ const HappyPack = require ( 'happypack' ) ;
15
+ const resolve = require ( 'resolve' ) ;
14
16
15
17
/**
16
18
* Enumerate loaders and their dependencies from this file to let the dependency validator
@@ -104,8 +106,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
104
106
105
107
if ( ! asset . allowOutsideOutDir ) {
106
108
const message = 'An asset cannot be written to a location outside of the output path. '
107
- + 'You can override this message by setting the `allowOutsideOutDir` '
108
- + 'property on the asset to true in the CLI configuration.' ;
109
+ + 'You can override this message by setting the `allowOutsideOutDir` '
110
+ + 'property on the asset to true in the CLI configuration.' ;
109
111
throw new SilentError ( message ) ;
110
112
}
111
113
}
@@ -163,13 +165,28 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
163
165
}
164
166
165
167
if ( buildOptions . buildOptimizer ) {
168
+ // Set the cache directory to the Build Optimizer dir, so that package updates will delete it.
169
+ const buildOptimizerDir = path . dirname (
170
+ resolve . sync ( '@angular-devkit/build-optimizer' , { basedir : projectRoot } ) ) ;
171
+ const cacheDirectory = path . resolve ( buildOptimizerDir , './.cache/' ) ;
172
+
166
173
extraRules . push ( {
167
174
test : / \. j s $ / ,
168
- use : [ {
169
- loader : '@angular-devkit/build-optimizer/webpack-loader' ,
170
- options : { sourceMap : buildOptions . sourcemaps }
171
- } ]
175
+ use : [ 'happypack/loader' ] ,
172
176
} ) ;
177
+ extraPlugins . push ( new HappyPack ( {
178
+ verbose : false ,
179
+ loaders : [
180
+ {
181
+ loader : 'cache-loader' ,
182
+ options : { cacheDirectory }
183
+ } ,
184
+ {
185
+ loader : '@angular-devkit/build-optimizer/webpack-loader' ,
186
+ options : { sourceMap : buildOptions . sourcemaps }
187
+ }
188
+ ] ,
189
+ } ) ) ;
173
190
}
174
191
175
192
if ( buildOptions . namedChunks ) {
0 commit comments