MCPcopy
hub / github.com/Meituan-Dianping/mpvue / apply

Method apply

src/server/webpack-plugin/client.js:12–69  ·  view source on GitHub ↗
(compiler)

Source from the content-addressed store, hash-verified

10 }
11
12 apply (compiler) {
13 compiler.plugin('emit', (compilation, cb) => {
14 const stats = compilation.getStats().toJson()
15
16 const allFiles = uniq(stats.assets
17 .map(a => a.name))
18
19 const initialFiles = uniq(Object.keys(stats.entrypoints)
20 .map(name => stats.entrypoints[name].assets)
21 .reduce((assets, all) => all.concat(assets), [])
22 .filter(isJS))
23
24 const asyncFiles = allFiles
25 .filter(isJS)
26 .filter(file => initialFiles.indexOf(file) < 0)
27
28 const manifest = {
29 publicPath: stats.publicPath,
30 all: allFiles,
31 initial: initialFiles,
32 async: asyncFiles,
33 modules: { /* [identifier: string]: Array<index: number> */ }
34 }
35
36 const assetModules = stats.modules.filter(m => m.assets.length)
37 const fileToIndex = file => manifest.all.indexOf(file)
38 stats.modules.forEach(m => {
39 // ignore modules duplicated in multiple chunks
40 if (m.chunks.length === 1) {
41 const cid = m.chunks[0]
42 const chunk = stats.chunks.find(c => c.id === cid)
43 if (!chunk || !chunk.files) {
44 return
45 }
46 const files = manifest.modules[hash(m.identifier)] = chunk.files.map(fileToIndex)
47 // find all asset modules associated with the same chunk
48 assetModules.forEach(m => {
49 if (m.chunks.some(id => id === cid)) {
50 files.push.apply(files, m.assets.map(fileToIndex))
51 }
52 })
53 }
54 })
55
56 // const debug = (file, obj) => {
57 // require('fs').writeFileSync(__dirname + '/' + file, JSON.stringify(obj, null, 2))
58 // }
59 // debug('stats.json', stats)
60 // debug('client-manifest.json', manifest)
61
62 const json = JSON.stringify(manifest, null, 2)
63 compilation.assets[this.options.filename] = {
64 source: () => json,
65 size: () => json.length
66 }
67 cb()
68 })
69 }

Callers 15

build.jsFile · 0.45
compileFunction · 0.45
build.jsFile · 0.45
compileFunction · 0.45
boundFnFunction · 0.45
onceFunction · 0.45
index.jsFile · 0.45
invokerFunction · 0.45
simpleNormalizeChildrenFunction · 0.45
normalizeArrayChildrenFunction · 0.45
onFunction · 0.45
eventsMixinFunction · 0.45

Calls 1

cbFunction · 0.50

Tested by 1

sendTasksFunction · 0.36