diff --git a/src/server/webpack-plugin/client.js b/src/server/webpack-plugin/client.js index 6f77b863b20..4d9b6813031 100644 --- a/src/server/webpack-plugin/client.js +++ b/src/server/webpack-plugin/client.js @@ -1,6 +1,6 @@ const hash = require('hash-sum') const uniq = require('lodash.uniq') -import { isJS, isCSS } from './util' +import { isJS, isCSS, onEmit } from './util' export default class VueSSRClientPlugin { constructor (options = {}) { @@ -10,7 +10,7 @@ export default class VueSSRClientPlugin { } apply (compiler) { - compiler.plugin('emit', (compilation, cb) => { + onEmit(compiler, 'vue-client-plugin', (compilation, cb) => { const stats = compilation.getStats().toJson() const allFiles = uniq(stats.assets diff --git a/src/server/webpack-plugin/server.js b/src/server/webpack-plugin/server.js index 8ffa58b03ee..a9a38337411 100644 --- a/src/server/webpack-plugin/server.js +++ b/src/server/webpack-plugin/server.js @@ -1,4 +1,4 @@ -import { validate, isJS } from './util' +import { validate, isJS, onEmit } from './util' export default class VueSSRServerPlugin { constructor (options = {}) { @@ -10,7 +10,7 @@ export default class VueSSRServerPlugin { apply (compiler) { validate(compiler) - compiler.plugin('emit', (compilation, cb) => { + onEmit(compiler, 'vue-server-plugin', (compilation, cb) => { const stats = compilation.getStats().toJson() const entryName = Object.keys(stats.entrypoints)[0] const entryInfo = stats.entrypoints[entryName] diff --git a/src/server/webpack-plugin/util.js b/src/server/webpack-plugin/util.js index d22e4b2c497..94a204a22b2 100644 --- a/src/server/webpack-plugin/util.js +++ b/src/server/webpack-plugin/util.js @@ -21,4 +21,14 @@ export const validate = compiler => { } } +export const onEmit = (compiler, name, hook) => { + if (compiler.hooks) { + // Webpack >= 4.0.0 + compiler.hooks.emit.tapAsync(name, hook) + } else { + // Webpack < 4.0.0 + compiler.plugin('emit', hook) + } +} + export { isJS, isCSS } from '../util'