Skip to content

Commit aa70fcd

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

File tree

3 files changed

+106
-7
lines changed

3 files changed

+106
-7
lines changed

package-lock.json

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
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",
@@ -114,8 +115,8 @@
114115
"@types/fs-extra": "^4.0.0",
115116
"@types/glob": "^5.0.29",
116117
"@types/jasmine": "2.5.45",
117-
"@types/lodash": "~4.14.50",
118118
"@types/loader-utils": "^1.1.0",
119+
"@types/lodash": "~4.14.50",
119120
"@types/minimist": "^1.2.0",
120121
"@types/mock-fs": "^3.6.30",
121122
"@types/node": "^6.0.84",
@@ -128,6 +129,7 @@
128129
"dtsgenerator": "^0.9.1",
129130
"eslint": "^3.11.0",
130131
"express": "^4.14.0",
132+
"happypack": "^4.0.0",
131133
"jasmine": "^2.6.0",
132134
"jasmine-spec-reporter": "^4.1.0",
133135
"license-checker": "^15.0.0",

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

Lines changed: 23 additions & 6 deletions
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
@@ -104,8 +106,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
104106

105107
if (!asset.allowOutsideOutDir) {
106108
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.';
109111
throw new SilentError(message);
110112
}
111113
}
@@ -163,13 +165,28 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
163165
}
164166

165167
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+
166173
extraRules.push({
167174
test: /\.js$/,
168-
use: [{
169-
loader: '@angular-devkit/build-optimizer/webpack-loader',
170-
options: { sourceMap: buildOptions.sourcemaps }
171-
}]
175+
use: ['happypack/loader'],
172176
});
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+
}));
173190
}
174191

175192
if (buildOptions.namedChunks) {

0 commit comments

Comments
 (0)