Skip to content

Commit

Permalink
refactor: remove unnecessary onEmit in old webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Feb 7, 2019
1 parent 2c763df commit eac6d02
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/webpack/src/plugins/vue/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack/src/plugins/vue/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validate, isJS, onEmit } from './util'
import { validate, isJS } from './util'

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

0 comments on commit eac6d02

Please sign in to comment.