Browse Source

[vue-server-renderer] ensure assets are unique (#5540)

* [vue-server-renderer] ensure assets are unique

* add lodash.uniq to devDependencies
dev
Pooya Parsa 8 years ago
committed by Evan You
parent
commit
1635ca7143
  1. 1
      package.json
  2. 1
      packages/vue-server-renderer/package.json
  3. 12
      src/server/webpack-plugin/client.js

1
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",

1
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"

12
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 => {

Loading…
Cancel
Save