Skip to content

Commit 58bf029

Browse files
committed
fix(build): hashes in prod builds now changes when ID change.
Fixes angular#2868. Fixes angular#3311.
1 parent acd4589 commit 58bf029

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

packages/angular-cli/blueprints/ng2/files/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@angular/http": "~2.3.1",
2121
"@angular/platform-browser": "~2.3.1",
2222
"@angular/platform-browser-dynamic": "~2.3.1",
23-
"@angular/router": "3.2.3",
23+
"@angular/router": "~3.3.1",
2424
"core-js": "^2.4.1",
2525
"rxjs": "5.0.0-rc.4",
2626
"ts-helpers": "^1.1.1",

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

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as path from 'path';
22
import * as webpack from 'webpack';
3-
const WebpackMd5Hash = require('webpack-md5-hash');
43
const ExtractTextPlugin = require('extract-text-webpack-plugin');
54
import {CompressionPlugin} from '../lib/webpack/compression-plugin';
65
const autoprefixer = require('autoprefixer');
@@ -30,7 +29,6 @@ export const getWebpackProdConfigPartial = function(projectRoot: string,
3029
},
3130
plugins: [
3231
new ExtractTextPlugin('[name].[chunkhash].bundle.css'),
33-
new WebpackMd5Hash(),
3432
new webpack.DefinePlugin({
3533
'process.env.NODE_ENV': JSON.stringify('production')
3634
}),

tests/e2e/assets/webpack/test-app-weird/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@angular/platform-browser": "~2.3.1",
1111
"@angular/platform-browser-dynamic": "~2.3.1",
1212
"@angular/platform-server": "~2.3.1",
13-
"@angular/router": "~3.2.3",
13+
"@angular/router": "~3.3.1",
1414
"@ngtools/webpack": "0.0.0",
1515
"core-js": "^2.4.1",
1616
"rxjs": "5.0.0-rc.4",

tests/e2e/assets/webpack/test-app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@angular/platform-browser": "~2.3.1",
1111
"@angular/platform-browser-dynamic": "~2.3.1",
1212
"@angular/platform-server": "~2.3.1",
13-
"@angular/router": "~3.2.3",
13+
"@angular/router": "~3.3.1",
1414
"@ngtools/webpack": "0.0.0",
1515
"core-js": "^2.4.1",
1616
"rxjs": "5.0.0-rc.4",

tests/e2e/tests/build/chunk-hash.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from 'fs';
2+
3+
import {ng} from '../../utils/process';
4+
import {writeFile} from '../../utils/fs';
5+
6+
7+
export default function() {
8+
const oldHashes: {[module: string]: string} = {};
9+
const newHashes: {[module: string]: string} = {};
10+
// First, collect the hashes.
11+
return ng('build', '--prod')
12+
.then(() => {
13+
fs.readdirSync('./dist')
14+
.forEach(name => {
15+
if (!name.match(/(main|inline|vendor)\.[a-z0-9]+\.bundle\.js/)) {
16+
return;
17+
}
18+
19+
const [module, hash] = name.split('.');
20+
oldHashes[module] = hash;
21+
});
22+
})
23+
.then(() => writeFile('src/app/app.component.css', 'body { background: red; }'))
24+
.then(() => ng('build', '--prod'))
25+
.then(() => {
26+
fs.readdirSync('./dist')
27+
.forEach(name => {
28+
if (!name.match(/(main|inline|vendor)\.[a-z0-9]+\.bundle\.js/)) {
29+
return;
30+
}
31+
32+
const [module, hash] = name.split('.');
33+
newHashes[module] = hash;
34+
});
35+
})
36+
.then(() => {
37+
console.log(' Validating hashes...');
38+
console.log(` Old hashes: ${JSON.stringify(oldHashes)}`);
39+
console.log(` New hashes: ${JSON.stringify(newHashes)}`);
40+
41+
Object.keys(oldHashes)
42+
.forEach(module => {
43+
if (oldHashes[module] == newHashes[module]) {
44+
throw new Error(`Module "${module}" did not change hash (${oldHashes[module]})...`);
45+
}
46+
});
47+
});
48+
}

0 commit comments

Comments
 (0)