Skip to content

Commit

Permalink
fix(build): hashes in prod builds now changes when ID change.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl committed Dec 17, 2016
1 parent acd4589 commit 58bf029
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/angular-cli/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@angular/http": "~2.3.1",
"@angular/platform-browser": "~2.3.1",
"@angular/platform-browser-dynamic": "~2.3.1",
"@angular/router": "3.2.3",
"@angular/router": "~3.3.1",
"core-js": "^2.4.1",
"rxjs": "5.0.0-rc.4",
"ts-helpers": "^1.1.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/angular-cli/models/webpack-build-production.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as path from 'path';
import * as webpack from 'webpack';
const WebpackMd5Hash = require('webpack-md5-hash');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
import {CompressionPlugin} from '../lib/webpack/compression-plugin';
const autoprefixer = require('autoprefixer');
Expand Down Expand Up @@ -30,7 +29,6 @@ export const getWebpackProdConfigPartial = function(projectRoot: string,
},
plugins: [
new ExtractTextPlugin('[name].[chunkhash].bundle.css'),
new WebpackMd5Hash(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/assets/webpack/test-app-weird/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@angular/platform-browser": "~2.3.1",
"@angular/platform-browser-dynamic": "~2.3.1",
"@angular/platform-server": "~2.3.1",
"@angular/router": "~3.2.3",
"@angular/router": "~3.3.1",
"@ngtools/webpack": "0.0.0",
"core-js": "^2.4.1",
"rxjs": "5.0.0-rc.4",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/assets/webpack/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@angular/platform-browser": "~2.3.1",
"@angular/platform-browser-dynamic": "~2.3.1",
"@angular/platform-server": "~2.3.1",
"@angular/router": "~3.2.3",
"@angular/router": "~3.3.1",
"@ngtools/webpack": "0.0.0",
"core-js": "^2.4.1",
"rxjs": "5.0.0-rc.4",
Expand Down
48 changes: 48 additions & 0 deletions tests/e2e/tests/build/chunk-hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as fs from 'fs';

import {ng} from '../../utils/process';
import {writeFile} from '../../utils/fs';


export default function() {
const oldHashes: {[module: string]: string} = {};
const newHashes: {[module: string]: string} = {};
// First, collect the hashes.
return ng('build', '--prod')
.then(() => {
fs.readdirSync('./dist')
.forEach(name => {
if (!name.match(/(main|inline|vendor)\.[a-z0-9]+\.bundle\.js/)) {
return;
}

const [module, hash] = name.split('.');
oldHashes[module] = hash;
});
})
.then(() => writeFile('src/app/app.component.css', 'body { background: red; }'))
.then(() => ng('build', '--prod'))
.then(() => {
fs.readdirSync('./dist')
.forEach(name => {
if (!name.match(/(main|inline|vendor)\.[a-z0-9]+\.bundle\.js/)) {
return;
}

const [module, hash] = name.split('.');
newHashes[module] = hash;
});
})
.then(() => {
console.log(' Validating hashes...');
console.log(` Old hashes: ${JSON.stringify(oldHashes)}`);
console.log(` New hashes: ${JSON.stringify(newHashes)}`);

Object.keys(oldHashes)
.forEach(module => {
if (oldHashes[module] == newHashes[module]) {
throw new Error(`Module "${module}" did not change hash (${oldHashes[module]})...`);
}
});
});
}

0 comments on commit 58bf029

Please sign in to comment.