Skip to content

Commit b7c4259

Browse files
pi0hefeng
authored and
hefeng
committed
feat(server, webpack-plugin): webpack 4 support (vuejs#7839)
SSR webpack 4 compat
1 parent c72ea4c commit b7c4259

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Diff for: src/server/webpack-plugin/client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const hash = require('hash-sum')
22
const uniq = require('lodash.uniq')
3-
import { isJS, isCSS } from './util'
3+
import { isJS, isCSS, onEmit } from './util'
44

55
export default class VueSSRClientPlugin {
66
constructor (options = {}) {
@@ -10,7 +10,7 @@ export default class VueSSRClientPlugin {
1010
}
1111

1212
apply (compiler) {
13-
compiler.plugin('emit', (compilation, cb) => {
13+
onEmit(compiler, 'vue-client-plugin', (compilation, cb) => {
1414
const stats = compilation.getStats().toJson()
1515

1616
const allFiles = uniq(stats.assets

Diff for: src/server/webpack-plugin/server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { validate, isJS } from './util'
1+
import { validate, isJS, onEmit } from './util'
22

33
export default class VueSSRServerPlugin {
44
constructor (options = {}) {
@@ -10,7 +10,7 @@ export default class VueSSRServerPlugin {
1010
apply (compiler) {
1111
validate(compiler)
1212

13-
compiler.plugin('emit', (compilation, cb) => {
13+
onEmit(compiler, 'vue-server-plugin', (compilation, cb) => {
1414
const stats = compilation.getStats().toJson()
1515
const entryName = Object.keys(stats.entrypoints)[0]
1616
const entryInfo = stats.entrypoints[entryName]

Diff for: src/server/webpack-plugin/util.js

+10
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ export const validate = compiler => {
2121
}
2222
}
2323

24+
export const onEmit = (compiler, name, hook) => {
25+
if (compiler.hooks) {
26+
// Webpack >= 4.0.0
27+
compiler.hooks.emit.tapAsync(name, hook)
28+
} else {
29+
// Webpack < 4.0.0
30+
compiler.plugin('emit', hook)
31+
}
32+
}
33+
2434
export { isJS, isCSS } from '../util'

0 commit comments

Comments
 (0)