Skip to content

Commit ba9bb79

Browse files
author
Pooya Parsa
committed
feat(server, webpack-plugin): webpack 4 support
4b4b442
1 parent 2534219 commit ba9bb79

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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 } from './util'
3+
import { isJS, 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

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]

src/server/webpack-plugin/util.js

+17
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,21 @@ 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.tap(name,
28+
(compilation) => new Promise((resolve, reject) => {
29+
try {
30+
hook(compilation, resolve)
31+
} catch (e) {
32+
reject(e)
33+
}
34+
}))
35+
} else {
36+
// Webpack < 4.0.0
37+
compiler.plugin('emit', hook)
38+
}
39+
}
40+
2441
export { isJS, isCSS } from '../util'

0 commit comments

Comments
 (0)