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