Skip to content

Commit

Permalink
feat(server, webpack-plugin): webpack 4 support (#7839)
Browse files Browse the repository at this point in the history
SSR webpack 4 compat
  • Loading branch information
pi0 authored and yyx990803 committed Apr 7, 2018
1 parent 575b6e7 commit ef0b250
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/server/webpack-plugin/client.js
Original file line number Diff line number Diff line change
@@ -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 = {}) {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/server/webpack-plugin/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate, isJS } from './util'
import { validate, isJS, onEmit } from './util'

export default class VueSSRServerPlugin {
constructor (options = {}) {
Expand All @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions src/server/webpack-plugin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit ef0b250

Please sign in to comment.