Skip to content

Commit 1635ca7

Browse files
pi0yyx990803
authored andcommitted
[vue-server-renderer] ensure assets are unique (vuejs#5540)
* [vue-server-renderer] ensure assets are unique * add lodash.uniq to devDependencies
1 parent d6c070d commit 1635ca7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"karma-webpack": "^2.0.1",
9797
"lodash": "^4.17.1",
9898
"lodash.template": "^4.4.0",
99+
"lodash.uniq": "^4.5.0",
99100
"lru-cache": "^4.0.2",
100101
"nightwatch": "^0.9.9",
101102
"nightwatch-helpers": "^1.2.0",

packages/vue-server-renderer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"hash-sum": "^1.0.2",
2323
"he": "^1.1.0",
2424
"lodash.template": "^4.4.0",
25+
"lodash.uniq": "^4.5.0",
2526
"resolve": "^1.2.0",
2627
"source-map": "0.5.6",
2728
"serialize-javascript": "^1.3.0"

src/server/webpack-plugin/client.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const hash = require('hash-sum')
2+
const uniq = require('lodash.uniq')
23
import { isJS } from './util'
34

45
export default class VueSSRClientPlugin {
@@ -12,13 +13,13 @@ export default class VueSSRClientPlugin {
1213
compiler.plugin('emit', (compilation, cb) => {
1314
const stats = compilation.getStats().toJson()
1415

15-
const allFiles = stats.assets
16-
.map(a => a.name)
16+
const allFiles = uniq(stats.assets
17+
.map(a => a.name))
1718

18-
const initialFiles = Object.keys(stats.entrypoints)
19+
const initialFiles = uniq(Object.keys(stats.entrypoints)
1920
.map(name => stats.entrypoints[name].assets)
2021
.reduce((assets, all) => all.concat(assets), [])
21-
.filter(isJS)
22+
.filter(isJS))
2223

2324
const asyncFiles = allFiles
2425
.filter(isJS)
@@ -39,6 +40,9 @@ export default class VueSSRClientPlugin {
3940
if (m.chunks.length === 1) {
4041
const cid = m.chunks[0]
4142
const chunk = stats.chunks.find(c => c.id === cid)
43+
if (!chunk || !chunk.files) {
44+
return
45+
}
4246
const files = manifest.modules[hash(m.identifier)] = chunk.files.map(fileToIndex)
4347
// find all asset modules associated with the same chunk
4448
assetModules.forEach(m => {

0 commit comments

Comments
 (0)