refactor: remove unnecessary onEmit in old webpack

This commit is contained in:
Clark Du 2019-02-07 17:26:43 +00:00
parent 2c763df176
commit eac6d022f5
3 changed files with 4 additions and 14 deletions

View File

@ -6,7 +6,7 @@
import hash from 'hash-sum'
import uniq from 'lodash/uniq'
import { isJS, isCSS, onEmit } from './util'
import { isJS, isCSS } from './util'
export default class VueSSRClientPlugin {
constructor(options = {}) {
@ -16,7 +16,7 @@ export default class VueSSRClientPlugin {
}
apply(compiler) {
onEmit(compiler, 'vue-client-plugin', (compilation, cb) => {
compiler.hooks.emit.tapAsync('vue-client-plugin', (compilation, cb) => {
const stats = compilation.getStats().toJson()
const allFiles = uniq(stats.assets

View File

@ -1,4 +1,4 @@
import { validate, isJS, onEmit } from './util'
import { validate, isJS } from './util'
export default class VueSSRServerPlugin {
constructor(options = {}) {
@ -10,7 +10,7 @@ export default class VueSSRServerPlugin {
apply(compiler) {
validate(compiler)
onEmit(compiler, 'vue-server-plugin', (compilation, cb) => {
compiler.hooks.emit.tapAsync('vue-server-plugin', (compilation, cb) => {
const stats = compilation.getStats().toJson()
const [entryName] = Object.keys(stats.entrypoints)
const entryInfo = stats.entrypoints[entryName]

View File

@ -22,16 +22,6 @@ 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 const isJS = file => /\.js(\?[^.]+)?$/.test(file)
export const isCSS = file => /\.css(\?[^.]+)?$/.test(file)