From 5887875975d2e6fc704156e65798f0f7265a1d38 Mon Sep 17 00:00:00 2001 From: zouyi6 Date: Mon, 12 Jun 2017 11:07:15 +0800 Subject: [PATCH 1/2] upgrade webpack to 2.x, it's uncompactable with 1.x --- template/client/app/router/routerConfig.js | 2 +- template/client/{index.html => index.ejs} | 1 + template/package.json | 7 +++++-- template/webpack.config.js | 6 +++--- template/webpack.dist.config.js | 11 +++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-) rename template/client/{index.html => index.ejs} (92%) diff --git a/template/client/app/router/routerConfig.js b/template/client/app/router/routerConfig.js index 21e8f7f..28cdf2a 100644 --- a/template/client/app/router/routerConfig.js +++ b/template/client/app/router/routerConfig.js @@ -4,7 +4,7 @@ export default [ name:'start', url:"/start", template:'', - lazyload:require("bundle?lazy&name=start!../components/start/start.js"), + lazyload:require("bundle-loader?lazy&name=start!../components/start/start.js"), tracking:{ key:'start' } diff --git a/template/client/index.html b/template/client/index.ejs similarity index 92% rename from template/client/index.html rename to template/client/index.ejs index c6fa67c..dc0a494 100755 --- a/template/client/index.html +++ b/template/client/index.ejs @@ -12,6 +12,7 @@ + <%= htmlWebpackPlugin.files.webpackManifest %> diff --git a/template/package.json b/template/package.json index a3db551..a49a753 100644 --- a/template/package.json +++ b/template/package.json @@ -21,6 +21,7 @@ "bundle-loader": "^0.5.4", "browser-sync": "^2.11.1", "chai": "^3.4.0", + "chunk-manifest-webpack-plugin": "^1.1.0", "connect-history-api-fallback": "^1.1.0", "css-loader": "^0.19.0", "file-loader": "^0.8.5", @@ -29,7 +30,7 @@ "gulp-rename": "^1.2.2", "gulp-template": "^3.0.0", "gulp-util": "^3.0.7", - "html-webpack-plugin": "^1.7.0", + "html-webpack-plugin": "^2.28.0", "karma": "^0.13.9", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^0.2.0", @@ -46,7 +47,7 @@ "run-sequence": "^1.1.0", "style-loader": "^0.12.2", "supports-color": "^3.1.2", - "webpack": "^1.9.5", + "webpack": "^2.6.1", "webpack-dev-middleware": "^1.4.0", "webpack-hot-middleware": "^2.6.0", "webpack-dev-server": "^1.15.1", @@ -54,6 +55,8 @@ "is-utf8": "^0.2.0", "http-proxy-middleware": "^0.13.0", "happypack": "^4.0.0-beta.1", + "webpack-manifest-plugin": "^1.1.0", + "webpack-md5-hash": "^0.0.5", "webpack-parallel-uglify-plugin": "^0.4.1" }, "scripts": { diff --git a/template/webpack.config.js b/template/webpack.config.js index d9ce3cc..9be37c0 100755 --- a/template/webpack.config.js +++ b/template/webpack.config.js @@ -92,12 +92,12 @@ module.exports = { new HappyPack({ id: 'img', threads: os.cpus().length, - loaders: ['file?name=assets/img/img-[hash].[ext]'] + loaders: ['file-loader?name=assets/img/img-[hash].[ext]'] }), new HappyPack({ id: 'html', threads: os.cpus().length, - loaders: ['raw'] + loaders: ['raw-loader'] }), new HappyPack({ id: 'font', @@ -108,7 +108,7 @@ module.exports = { // It also adds hash to all injected assets so we don't have problems // with cache purging during deployment. new HtmlWebpackPlugin({ - template: 'client/index.html', + template: 'client/index.ejs', inject: 'body', hash: true }), diff --git a/template/webpack.dist.config.js b/template/webpack.dist.config.js index d5ca528..ef8d71e 100755 --- a/template/webpack.dist.config.js +++ b/template/webpack.dist.config.js @@ -5,6 +5,9 @@ var customConfig = require('./custom.env.config'); var os = require('os'); var ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin'); +var ManifestPlugin = require('webpack-manifest-plugin'); +var ChunkManifestPlugin = require('chunk-manifest-webpack-plugin'); +var WebpackMd5Hash = require('webpack-md5-hash'); var distPath = customConfig.distPath; @@ -41,6 +44,14 @@ config.plugins = config.plugins.concat([ 'NODE_ENV': JSON.stringify('sit'), 'DEBUG': false } + }), + //引入manifest + new WebpackMd5Hash(), + new ManifestPlugin(), + new ChunkManifestPlugin({ + filename: "chunk-manifest.json", + manifestVariable: "webpackManifest", + inlineManifest: true }) ]); From c88bb504ef05733cbe9fcfd15491ee47c939b22d Mon Sep 17 00:00:00 2001 From: zouyi6 Date: Mon, 12 Jun 2017 11:14:20 +0800 Subject: [PATCH 2/2] use chunkhash --- template/webpack.config.js | 4 ++-- template/webpack.dist.config.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/template/webpack.config.js b/template/webpack.config.js index 9be37c0..d8988ff 100755 --- a/template/webpack.config.js +++ b/template/webpack.config.js @@ -92,7 +92,7 @@ module.exports = { new HappyPack({ id: 'img', threads: os.cpus().length, - loaders: ['file-loader?name=assets/img/img-[hash].[ext]'] + loaders: ['file-loader?name=assets/img/img-[chunkhash].[ext]'] }), new HappyPack({ id: 'html', @@ -119,7 +119,7 @@ module.exports = { }), new webpack.optimize.CommonsChunkPlugin({ - name: 'vendor', + name: ['vendor','manifest'], minChunks: function (module, count) { return module.resource && module.resource.indexOf(path.resolve(__dirname, 'client')) === -1; } diff --git a/template/webpack.dist.config.js b/template/webpack.dist.config.js index ef8d71e..07eaecb 100755 --- a/template/webpack.dist.config.js +++ b/template/webpack.dist.config.js @@ -12,8 +12,8 @@ var WebpackMd5Hash = require('webpack-md5-hash'); var distPath = customConfig.distPath; config.output = { - filename: '[name].bundle.js', - chunkFilename:'[name].min.js', + filename: '[name].[chunkhash].bundle.js', + chunkFilename:'[name].[chunkhash].min.js', publicPath: '', path: distPath };