From 5dced21b0792c123734213d6dd641acbe6e915eb Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sat, 7 Apr 2018 08:53:59 +0430 Subject: [PATCH] feat(server, webpack-plugin): webpack 4 support (#7839) SSR webpack 4 compat --- src/server/webpack-plugin/client.js | 4 ++-- src/server/webpack-plugin/server.js | 4 ++-- src/server/webpack-plugin/util.js | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/webpack-plugin/client.js b/src/server/webpack-plugin/client.js index 6f77b863b2..4d9b681303 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 8ffa58b03e..a9a3833741 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 d22e4b2c49..94a204a22b 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'