Skip to content

Commit 8e9abf9

Browse files
authored
fix(build): hashes in prod builds now changes when ID change. (angular#3609)
1 parent 0954788 commit 8e9abf9

File tree

11 files changed

+68
-21
lines changed

11 files changed

+68
-21
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
@@ -309,6 +309,7 @@ export class AotPlugin implements Tapable {
309309
Object.keys(allLazyRoutes)
310310
.forEach(k => {
311311
const lazyRoute = allLazyRoutes[k];
312+
k = k.split('#')[0];
312313
if (this.skipCodeGeneration) {
313314
this._lazyRoutes[k] = lazyRoute;
314315
} 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/models/webpack-build-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export function makeCssLoaders(stylePaths: string[] = []) {
7878
// load global css as css files
7979
cssLoaders.push(...baseRules.map(({test, loaders}) => ({
8080
include: stylePaths, test, loaders: ExtractTextPlugin.extract({
81+
remove: false,
8182
loader: ['css-loader', ...commonLoaders, ...loaders],
8283
fallbackLoader: 'style-loader'
8384
})

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|styles|\d+)\.[a-z0-9]+\.bundle\.(js|css)/)) {
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|styles|\d+)\.[a-z0-9]+\.bundle\.(js|css)/)) {
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+
}
+3-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1+
import {normalize} from 'path';
12
import {createProjectFromAsset} from '../../../utils/assets';
23
import {exec} from '../../../utils/process';
34
import {expectFileSizeToBeUnder} from '../../../utils/fs';
45

56

67
export default function(skipCleaning: () => void) {
7-
if (process.platform.startsWith('win')) {
8-
// Disable the test on Windows.
9-
return Promise.resolve();
10-
}
11-
128
return Promise.resolve()
139
.then(() => createProjectFromAsset('webpack/test-app'))
14-
.then(() => exec('node_modules/.bin/webpack', '-p'))
15-
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 400000))
10+
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p'))
11+
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 420000))
1612
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000))
1713
.then(() => skipCleaning());
1814
}

tests/e2e/tests/packages/webpack/weird.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {normalize} from 'path';
2+
13
import {createProjectFromAsset} from '../../../utils/assets';
24
import {exec} from '../../../utils/process';
35
import {updateJsonFile} from '../../../utils/project';
@@ -6,14 +8,9 @@ import {expectToFail} from '../../../utils/utils';
68

79

810
export default function(skipCleaning: () => void) {
9-
if (process.platform.startsWith('win')) {
10-
// Disable the test on Windows.
11-
return Promise.resolve();
12-
}
13-
1411
return Promise.resolve()
1512
.then(() => createProjectFromAsset('webpack/test-app-weird'))
16-
.then(() => exec('node_modules/.bin/webpack', '-p'))
13+
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p'))
1714
.then(() => expectFileToExist('dist/app.main.js'))
1815
.then(() => expectFileToExist('dist/0.app.main.js'))
1916
.then(() => expectFileToExist('dist/1.app.main.js'))
@@ -25,7 +22,7 @@ export default function(skipCleaning: () => void) {
2522
.then(() => updateJsonFile('aotplugin.config.json', json => {
2623
json['skipCodeGeneration'] = true;
2724
}))
28-
.then(() => exec('node_modules/.bin/webpack', '-p'))
25+
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p'))
2926
.then(() => expectFileToExist('dist/app.main.js'))
3027
.then(() => expectFileToExist('dist/0.app.main.js'))
3128
.then(() => expectFileToExist('dist/1.app.main.js'))

0 commit comments

Comments
 (0)