diff --git a/package.json b/package.json index e3d29450..a6d98cae 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "karma-webpack": "^2.0.1", "lodash": "^4.17.1", "lodash.template": "^4.4.0", + "lodash.uniq": "^4.5.0", "lru-cache": "^4.0.2", "nightwatch": "^0.9.9", "nightwatch-helpers": "^1.2.0", diff --git a/packages/vue-server-renderer/package.json b/packages/vue-server-renderer/package.json index 75ee129f..eda0cd3f 100644 --- a/packages/vue-server-renderer/package.json +++ b/packages/vue-server-renderer/package.json @@ -22,6 +22,7 @@ "hash-sum": "^1.0.2", "he": "^1.1.0", "lodash.template": "^4.4.0", + "lodash.uniq": "^4.5.0", "resolve": "^1.2.0", "source-map": "0.5.6", "serialize-javascript": "^1.3.0" diff --git a/src/server/webpack-plugin/client.js b/src/server/webpack-plugin/client.js index 02d1fb6b..5f2cd4bd 100644 --- a/src/server/webpack-plugin/client.js +++ b/src/server/webpack-plugin/client.js @@ -1,4 +1,5 @@ const hash = require('hash-sum') +const uniq = require('lodash.uniq') import { isJS } from './util' export default class VueSSRClientPlugin { @@ -12,13 +13,13 @@ export default class VueSSRClientPlugin { compiler.plugin('emit', (compilation, cb) => { const stats = compilation.getStats().toJson() - const allFiles = stats.assets - .map(a => a.name) + const allFiles = uniq(stats.assets + .map(a => a.name)) - const initialFiles = Object.keys(stats.entrypoints) + const initialFiles = uniq(Object.keys(stats.entrypoints) .map(name => stats.entrypoints[name].assets) .reduce((assets, all) => all.concat(assets), []) - .filter(isJS) + .filter(isJS)) const asyncFiles = allFiles .filter(isJS) @@ -39,6 +40,9 @@ export default class VueSSRClientPlugin { if (m.chunks.length === 1) { const cid = m.chunks[0] const chunk = stats.chunks.find(c => c.id === cid) + if (!chunk || !chunk.files) { + return + } const files = manifest.modules[hash(m.identifier)] = chunk.files.map(fileToIndex) // find all asset modules associated with the same chunk assetModules.forEach(m => {