1
1
import * as webpack from 'webpack' ;
2
2
import * as path from 'path' ;
3
+ import * as os from 'os' ;
3
4
import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
4
5
import { NamedLazyChunksWebpackPlugin } from '../../plugins/named-lazy-chunks-webpack-plugin' ;
5
6
import { extraEntryParser , getOutputHashFormat , AssetPattern } from './utils' ;
@@ -11,6 +12,7 @@ import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin';
11
12
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
12
13
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
13
14
const SilentError = require ( 'silent-error' ) ;
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
@@ -163,12 +166,20 @@ 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
176
use : [ {
177
+ loader : 'cache-loader' ,
178
+ options : { cacheDirectory }
179
+ } , {
169
180
loader : '@angular-devkit/build-optimizer/webpack-loader' ,
170
181
options : { sourceMap : buildOptions . sourcemaps }
171
- } ]
182
+ } ] ,
172
183
} ) ;
173
184
}
174
185
0 commit comments