From daf79c4b7c663c3693063c83d9363d5bf4fbdf31 Mon Sep 17 00:00:00 2001 From: zema1 Date: Sat, 23 Dec 2017 22:18:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86vendor=5Fdll=E7=9A=84hash=E6=94=BE?= =?UTF-8?q?=E5=9C=A8=E6=96=87=E4=BB=B6=E5=90=8D=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- build/webpack.base.conf.js | 15 +++++++++++---- build/webpack.dll.conf.js | 6 +++--- package.json | 1 + src/pages/oj/index.html | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 52061c5ec..3ac4b4b4d 100644 --- a/.gitignore +++ b/.gitignore @@ -66,5 +66,5 @@ test.vue # build vendor-manifest.json -vendor.dll.js +vendor.dll*.js diff --git a/build/webpack.base.conf.js b/build/webpack.base.conf.js index fa1288b58..e239a8581 100644 --- a/build/webpack.base.conf.js +++ b/build/webpack.base.conf.js @@ -1,5 +1,6 @@ 'use strict' const path = require('path') +const glob = require('glob') const webpack = require('webpack') const utils = require('./utils') const config = require('../config') @@ -10,7 +11,7 @@ function resolve (dir) { return path.join(__dirname, '..', dir) } -function getEntries() { +function getEntries () { const base = { 'oj': ['./src/pages/oj/index.js'], 'admin': ['./src/pages/admin/index.js'] @@ -22,6 +23,8 @@ function getEntries() { } return base } + +// get all entries const entries = getEntries() console.log("All entries: ") Object.keys(entries).forEach(entry => { @@ -32,6 +35,11 @@ Object.keys(entries).forEach(entry => { console.log() }) +// prepare vendor asserts +const globOptions = {cwd: resolve('static/js')}; +let vendorAssets = glob.sync('vendor.dll.*.js', globOptions); +vendorAssets = vendorAssets.map(file => 'static/js/' + file) + module.exports = { entry: entries, @@ -107,10 +115,9 @@ module.exports = { manifest: require('./vendor-manifest.json') }), new HtmlWebpackIncludeAssetsPlugin({ - assets: ['static/js/vendor.dll.js'], + assets: [vendorAssets[0]], files: ['index.html', 'admin/index.html'], - append: false, - hash: true + append: false }), ] } diff --git a/build/webpack.dll.conf.js b/build/webpack.dll.conf.js index e73c61ede..4e035192d 100644 --- a/build/webpack.dll.conf.js +++ b/build/webpack.dll.conf.js @@ -23,8 +23,8 @@ module.exports = { }, output: { path: path.join(__dirname, '../static/js'), - filename: '[name].dll.js', - library: '[name]_dll', + filename: '[name].dll.[hash:7].js', + library: '[name]_[hash]_dll', }, plugins: [ new webpack.DefinePlugin({ @@ -40,7 +40,7 @@ module.exports = { new webpack.DllPlugin({ context: __dirname, path: path.join(__dirname, '[name]-manifest.json'), - name: '[name]_dll', + name: '[name]_[hash]_dll', }) ] }; diff --git a/package.json b/package.json index 6a8fce543..e7990caeb 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^1.1.4", "friendly-errors-webpack-plugin": "^1.6.1", + "glob": "^7.1.2", "html-webpack-include-assets-plugin": "^1.0.2", "html-webpack-plugin": "^2.30.1", "http-proxy-middleware": "^0.17.3", diff --git a/src/pages/oj/index.html b/src/pages/oj/index.html index a682688d2..ed482f937 100644 --- a/src/pages/oj/index.html +++ b/src/pages/oj/index.html @@ -8,7 +8,7 @@ - +