From ba9bb795da38adda84c5d9656fca5de3ff4dfc02 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 16 Mar 2018 10:45:43 +0330 Subject: [PATCH 1/2] feat(server, webpack-plugin): webpack 4 support 4b4b442 --- src/server/webpack-plugin/client.js | 4 ++-- src/server/webpack-plugin/server.js | 4 ++-- src/server/webpack-plugin/util.js | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/server/webpack-plugin/client.js b/src/server/webpack-plugin/client.js index 5f2cd4bd6c6..b8973369048 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 } from './util' +import { isJS, 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..729f55136c2 100644 --- a/src/server/webpack-plugin/util.js +++ b/src/server/webpack-plugin/util.js @@ -21,4 +21,21 @@ export const validate = compiler => { } } +export const onEmit = (compiler, name, hook) => { + if (compiler.hooks) { + // Webpack >= 4.0.0 + compiler.hooks.emit.tap(name, + (compilation) => new Promise((resolve, reject) => { + try { + hook(compilation, resolve) + } catch (e) { + reject(e) + } + })) + } else { + // Webpack < 4.0.0 + compiler.plugin('emit', hook) + } +} + export { isJS, isCSS } from '../util' From 9cfabe17062d31f3141729eaa2ee16ac6c24d13b Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 16 Mar 2018 22:24:50 +0330 Subject: [PATCH 2/2] refactor(server, webpack-plugin): use tapAsync --- src/server/webpack-plugin/util.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/server/webpack-plugin/util.js b/src/server/webpack-plugin/util.js index 729f55136c2..94a204a22b2 100644 --- a/src/server/webpack-plugin/util.js +++ b/src/server/webpack-plugin/util.js @@ -24,14 +24,7 @@ export const validate = compiler => { export const onEmit = (compiler, name, hook) => { if (compiler.hooks) { // Webpack >= 4.0.0 - compiler.hooks.emit.tap(name, - (compilation) => new Promise((resolve, reject) => { - try { - hook(compilation, resolve) - } catch (e) { - reject(e) - } - })) + compiler.hooks.emit.tapAsync(name, hook) } else { // Webpack < 4.0.0 compiler.plugin('emit', hook)