Skip to content

Commit 521e4e7

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

File tree

8 files changed

+60
-7
lines changed

8 files changed

+60
-7
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
"walk-sync": "^0.2.6",
123123
"webpack": "2.1.0-beta.25",
124124
"webpack-dev-server": "2.1.0-beta.9",
125-
"webpack-md5-hash": "0.0.5",
126125
"webpack-merge": "^0.14.0",
127126
"webpack-sources": "^0.1.3",
128127
"yam": "0.0.18"

packages/@ngtools/webpack/src/plugin.ts

+1
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export class AotPlugin implements Tapable {
310310
Object.keys(allLazyRoutes)
311311
.forEach(k => {
312312
const lazyRoute = allLazyRoutes[k];
313+
k = k.split('#')[0];
313314
if (this.skipCodeGeneration) {
314315
this._lazyRoutes[k] = lazyRoute;
315316
} else {

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
}),

packages/angular-cli/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
"walk-sync": "^0.2.6",
102102
"webpack": "2.1.0-beta.25",
103103
"webpack-dev-server": "2.1.0-beta.9",
104-
"webpack-md5-hash": "0.0.5",
105104
"webpack-merge": "^0.14.0",
106105
"webpack-sources": "^0.1.3",
107106
"yam": "0.0.18"

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

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

0 commit comments

Comments
 (0)