-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.js
More file actions
43 lines (36 loc) · 1.34 KB
/
plugin.js
File metadata and controls
43 lines (36 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const SpikeUtil = require('..')
const EventEmitter = require('events')
module.exports = class TestPlugin extends EventEmitter {
constructor (opts = {}) {
super()
this.injectFile = opts.injectFile
}
apply (compiler) {
this.util = new SpikeUtil(compiler.options)
this.util.runAll(compiler, this.run.bind(this))
this.emit('getOutputPath', this.util.getOutputPath(this.injectFile))
this.emit('getSourcePath', this.util.getSourcePath('index.txt'))
this.emit('isFileIgnored', this.util.isFileIgnored('/views/ignoreme.txt'))
this.emit('matchGlobs', this.util.matchGlobs(['a/foo', 'a/bar', 'b/foo'], ['a/*']))
compiler.plugin('make', (compilation, done) => {
this.util.addFilesAsWebpackEntries(compilation, this.injectFile)
.then(() => this.emit('addFilesAsWebpackEntries', compilation))
.done(() => done(), done)
})
compiler.plugin('compilation', (compilation) => {
compilation.plugin('optimize-chunk-assets', (chunks, done) => {
this.util.removeAssets(compilation, this.injectFile, chunks)
this.emit('removeAssets')
done()
})
})
compiler.plugin('emit', (compilation, done) => {
this.util.modifyOutputPath('views/changepath.html', 'views/changed.html')
done()
})
}
run (compilation, done) {
this.emit('runAll', true)
done()
}
}