Skip to content

Commit 73ee829

Browse files
committed
re-implement cache busting mechanism, add --disable-cache-bus / -dcb flag to disable it
1 parent aca0345 commit 73ee829

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

packages/angular-cli/commands/build.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface BuildOptions {
1717
i18nFormat?: string;
1818
locale?: string;
1919
deployUrl?: string;
20+
disableCacheBust?: boolean;
2021
}
2122

2223
const BuildCommand = Command.extend({
@@ -31,21 +32,22 @@ const BuildCommand = Command.extend({
3132
default: 'development',
3233
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
3334
},
34-
{ name: 'environment', type: String, default: '', aliases: ['e'] },
35-
{ name: 'output-path', type: 'Path', default: null, aliases: ['o'] },
36-
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
37-
{ name: 'watcher', type: String },
38-
{ name: 'suppress-sizes', type: Boolean, default: false },
39-
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
40-
{ name: 'aot', type: Boolean, default: false },
41-
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
42-
{ name: 'vendor-chunk', type: Boolean, default: true },
43-
{ name: 'verbose', type: Boolean, default: false },
44-
{ name: 'progress', type: Boolean, default: true },
45-
{ name: 'i18n-file', type: String, default: null },
46-
{ name: 'i18n-format', type: String, default: null },
47-
{ name: 'locale', type: String, default: null },
48-
{ name: 'deploy-url', type: String, default: null, aliases: ['d'] }
35+
{ name: 'environment', type: String, default: '', aliases: ['e'] },
36+
{ name: 'output-path', type: 'Path', default: null, aliases: ['o'] },
37+
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
38+
{ name: 'watcher', type: String },
39+
{ name: 'suppress-sizes', type: Boolean, default: false },
40+
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
41+
{ name: 'aot', type: Boolean, default: false },
42+
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
43+
{ name: 'vendor-chunk', type: Boolean, default: true },
44+
{ name: 'verbose', type: Boolean, default: false },
45+
{ name: 'progress', type: Boolean, default: true },
46+
{ name: 'i18n-file', type: String, default: null },
47+
{ name: 'i18n-format', type: String, default: null },
48+
{ name: 'locale', type: String, default: null },
49+
{ name: 'deploy-url', type: String, default: null, aliases: ['d'] },
50+
{ name: 'disable-cache-bust', type: Boolean, default: false, aliases: ['dcb'], description: 'Disable webpack\'s [chunkhash] cache bust feature in prod build.' }
4951
],
5052

5153
run: function (commandOptions: BuildOptions) {

packages/angular-cli/models/webpack-build-production.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ declare module 'webpack' {
1818
export const getWebpackProdConfigPartial = function(projectRoot: string,
1919
appConfig: any,
2020
sourcemap: boolean,
21-
verbose: any) {
21+
verbose: any,
22+
disableCacheBust: boolean) {
2223
const appRoot = path.resolve(projectRoot, appConfig.root);
2324

2425
return {
2526
output: {
26-
filename: '[name].bundle.js',
27-
sourceMapFilename: '[name].bundle.map',
28-
chunkFilename: '[id].chunk.js'
27+
filename: disableCacheBust ? '[name].bundle.js' : '[name].[chunkhash].bundle.js',
28+
sourceMapFilename: disableCacheBust ? '[name].bundle.map' : '[name].[chunkhash].bundle.map',
29+
chunkFilename: disableCacheBust ? '[id].chunk.js' : '[id].[chunkhash].chunk.js'
2930
},
3031
plugins: [
31-
new ExtractTextPlugin('[name].bundle.css'),
32+
new ExtractTextPlugin(disableCacheBust ? '[name].bundle.css' : '[name].[chunkhash].bundle.css'),
3233
new webpack.DefinePlugin({
3334
'process.env.NODE_ENV': JSON.stringify('production')
3435
}),

packages/angular-cli/models/webpack-config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class NgCliWebpackConfig {
3232
vendorChunk = false,
3333
verbose = false,
3434
progress = true,
35-
deployUrl?: string
35+
deployUrl?: string,
36+
disableCacheBust = false
3637
) {
3738
const config: CliConfig = CliConfig.fromProject();
3839
const appConfig = config.config.apps[0];
@@ -51,7 +52,7 @@ export class NgCliWebpackConfig {
5152
progress
5253
);
5354
let targetConfigPartial = this.getTargetConfig(
54-
this.ngCliProject.root, appConfig, sourcemap, verbose
55+
this.ngCliProject.root, appConfig, sourcemap, verbose, disableCacheBust
5556
);
5657
const typescriptConfigPartial = isAoT
5758
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale)
@@ -74,12 +75,12 @@ export class NgCliWebpackConfig {
7475
);
7576
}
7677

77-
getTargetConfig(projectRoot: string, appConfig: any, sourcemap: boolean, verbose: boolean): any {
78+
getTargetConfig(projectRoot: string, appConfig: any, sourcemap: boolean, verbose: boolean, disableCacheBust: boolean): any {
7879
switch (this.target) {
7980
case 'development':
8081
return getWebpackDevConfigPartial(projectRoot, appConfig);
8182
case 'production':
82-
return getWebpackProdConfigPartial(projectRoot, appConfig, sourcemap, verbose);
83+
return getWebpackProdConfigPartial(projectRoot, appConfig, sourcemap, verbose, disableCacheBust);
8384
default:
8485
throw new Error("Invalid build target. Only 'development' and 'production' are available.");
8586
}

packages/angular-cli/tasks/build-webpack.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export default <any>Task.extend({
3434
runTaskOptions.vendorChunk,
3535
runTaskOptions.verbose,
3636
runTaskOptions.progress,
37-
deployUrl
37+
deployUrl,
38+
runTaskOptions.disableCacheBust
3839
).config;
3940

4041
const webpackCompiler: any = webpack(config);

0 commit comments

Comments
 (0)