2016-10-23 16:42:13 +00:00
|
|
|
|
|
|
|
// watch and trigger file remove event
|
|
|
|
// see: https://github.com/webpack/webpack/issues/1533
|
|
|
|
|
|
|
|
export default class WatchRemoveEventPlugin {
|
|
|
|
constructor () {
|
|
|
|
this.removedFiles = []
|
|
|
|
}
|
|
|
|
|
|
|
|
apply (compiler) {
|
|
|
|
compiler.removedFiles = []
|
|
|
|
|
2016-12-28 18:16:52 +00:00
|
|
|
if (!compiler.watchFileSystem) return
|
|
|
|
|
|
|
|
const { watchFileSystem } = compiler
|
|
|
|
const { watch } = watchFileSystem
|
|
|
|
|
|
|
|
watchFileSystem.watch = (files, dirs, missing, startTime, options, callback, callbackUndelayed) => {
|
|
|
|
const result = watch.call(watchFileSystem, files, dirs, missing, startTime, options, (...args) => {
|
|
|
|
compiler.removedFiles = this.removedFiles
|
|
|
|
this.removedFiles = []
|
|
|
|
callback(...args)
|
|
|
|
}, callbackUndelayed)
|
|
|
|
|
|
|
|
const watchpack = watchFileSystem.watcher
|
2016-12-31 19:40:18 +00:00
|
|
|
watchpack.on('remove', (file) => {
|
|
|
|
this.removedFiles.push(file)
|
2016-12-28 18:16:52 +00:00
|
|
|
})
|
|
|
|
return result
|
|
|
|
}
|
2016-10-23 16:42:13 +00:00
|
|
|
}
|
2016-12-28 18:16:52 +00:00
|
|
|
}
|