Skip to content

Commit 26de777

Browse files
committed
feat(@angular/cli): use cache and parallelization for build-optimizer
1 parent 6f2c865 commit 26de777

File tree

5 files changed

+118
-7
lines changed

5 files changed

+118
-7
lines changed

package-lock.json

+80
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@angular-devkit/schematics": "~0.0.51",
4747
"@schematics/angular": "~0.1.16",
4848
"autoprefixer": "^7.2.3",
49+
"cache-loader": "^1.2.0",
4950
"chalk": "~2.2.0",
5051
"circular-dependency-plugin": "^4.2.1",
5152
"clean-css": "^4.1.9",
@@ -61,6 +62,7 @@
6162
"file-loader": "^1.1.5",
6263
"fs-extra": "^4.0.0",
6364
"glob": "^7.0.3",
65+
"happypack": "^4.0.0",
6466
"html-webpack-plugin": "^2.29.0",
6567
"istanbul-instrumenter-loader": "^3.0.0",
6668
"karma-source-map-support": "^1.2.0",
@@ -114,8 +116,8 @@
114116
"@types/fs-extra": "^4.0.0",
115117
"@types/glob": "^5.0.29",
116118
"@types/jasmine": "2.5.45",
117-
"@types/lodash": "~4.14.50",
118119
"@types/loader-utils": "^1.1.0",
120+
"@types/lodash": "~4.14.50",
119121
"@types/minimist": "^1.2.0",
120122
"@types/mock-fs": "^3.6.30",
121123
"@types/node": "^6.0.84",

packages/@angular/cli/models/webpack-configs/common.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin';
1111
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
1212
const CircularDependencyPlugin = require('circular-dependency-plugin');
1313
const SilentError = require('silent-error');
14+
const HappyPack = require('happypack');
15+
const resolve = require('resolve');
1416

1517
/**
1618
* Enumerate loaders and their dependencies from this file to let the dependency validator
@@ -20,6 +22,7 @@ const SilentError = require('silent-error');
2022
* require('raw-loader')
2123
* require('url-loader')
2224
* require('file-loader')
25+
* require('cache-loader')
2326
* require('@angular-devkit/build-optimizer')
2427
*/
2528

@@ -104,8 +107,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
104107

105108
if (!asset.allowOutsideOutDir) {
106109
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.';
109112
throw new SilentError(message);
110113
}
111114
}
@@ -163,13 +166,28 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
163166
}
164167

165168
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+
166174
extraRules.push({
167175
test: /\.js$/,
168-
use: [{
169-
loader: '@angular-devkit/build-optimizer/webpack-loader',
170-
options: { sourceMap: buildOptions.sourcemaps }
171-
}]
176+
use: ['happypack/loader'],
172177
});
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+
}));
173191
}
174192

175193
if (buildOptions.namedChunks) {

packages/@angular/cli/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@ngtools/webpack": "1.10.0-beta.1",
3535
"@schematics/angular": "~0.1.16",
3636
"autoprefixer": "^7.2.3",
37+
"cache-loader": "^1.2.0",
3738
"chalk": "~2.2.0",
3839
"circular-dependency-plugin": "^4.2.1",
3940
"clean-css": "^4.1.9",
@@ -48,6 +49,7 @@
4849
"file-loader": "^1.1.5",
4950
"fs-extra": "^4.0.0",
5051
"glob": "^7.0.3",
52+
"happypack": "^4.0.0",
5153
"html-webpack-plugin": "^2.29.0",
5254
"karma-source-map-support": "^1.2.0",
5355
"less": "^2.7.2",

packages/@angular/cli/tasks/eject.ts

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
2727
const SilentError = require('silent-error');
2828
const CircularDependencyPlugin = require('circular-dependency-plugin');
2929
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
30+
const HappyPlugin = require('happypack');
3031
const Task = require('../ember-cli/lib/models/task');
3132

3233
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
@@ -171,6 +172,10 @@ class JsonWebpackSerializer {
171172
return plugin.options;
172173
}
173174

175+
private _happyPlugin(plugin: any) {
176+
return plugin.config;
177+
}
178+
174179
private _pluginsReplacer(plugins: any[]) {
175180
return plugins.map(plugin => {
176181
let args = plugin.options || undefined;
@@ -255,6 +260,10 @@ class JsonWebpackSerializer {
255260
args = this._uglifyjsPlugin(plugin);
256261
this.variableImports['uglifyjs-webpack-plugin'] = 'UglifyJsPlugin';
257262
break;
263+
case HappyPlugin:
264+
args = this._happyPlugin(plugin);
265+
this.variableImports['happypack'] = 'HappyPlugin';
266+
break;
258267
case SubresourceIntegrityPlugin:
259268
this.variableImports['webpack-subresource-integrity'] = 'SubresourceIntegrityPlugin';
260269
break;

0 commit comments

Comments
 (0)