@@ -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
@@ -20,6 +22,7 @@ const SilentError = require('silent-error');
20
22
* require('raw-loader')
21
23
* require('url-loader')
22
24
* require('file-loader')
25
+ * require('cache-loader')
23
26
* require('@angular-devkit/build-optimizer')
24
27
*/
25
28
@@ -104,8 +107,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
104
107
105
108
if ( ! asset . allowOutsideOutDir ) {
106
109
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.' ;
110
+ + 'You can override this message by setting the `allowOutsideOutDir` '
111
+ + 'property on the asset to true in the CLI configuration.' ;
109
112
throw new SilentError ( message ) ;
110
113
}
111
114
}
@@ -163,13 +166,28 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
163
166
}
164
167
165
168
if ( buildOptions . buildOptimizer ) {
169
+ // Set the cache directory to the Build Optimizer dir, so that package updates will delete it.
170
+ const buildOptimizerDir = path . dirname (
171
+ resolve . sync ( '@angular-devkit/build-optimizer' , { basedir : projectRoot } ) ) ;
172
+ const cacheDirectory = path . resolve ( buildOptimizerDir , './.cache/' ) ;
173
+
166
174
extraRules . push ( {
167
175
test : / \. j s $ / ,
168
- use : [ {
169
- loader : '@angular-devkit/build-optimizer/webpack-loader' ,
170
- options : { sourceMap : buildOptions . sourcemaps }
171
- } ]
176
+ use : [ 'happypack/loader' ] ,
172
177
} ) ;
178
+ extraPlugins . push ( new HappyPack ( {
179
+ verbose : false ,
180
+ loaders : [
181
+ {
182
+ loader : 'cache-loader' ,
183
+ options : { cacheDirectory }
184
+ } ,
185
+ {
186
+ loader : '@angular-devkit/build-optimizer/webpack-loader' ,
187
+ options : { sourceMap : buildOptions . sourcemaps }
188
+ }
189
+ ] ,
190
+ } ) ) ;
173
191
}
174
192
175
193
if ( buildOptions . namedChunks ) {
0 commit comments