2017-01-12 15:39:04 +00:00
|
|
|
import { resolve, join } from 'path'
|
2016-12-27 23:28:19 +00:00
|
|
|
|
2016-10-23 16:42:13 +00:00
|
|
|
export default class WatchPagesPlugin {
|
|
|
|
constructor (dir) {
|
|
|
|
this.dir = resolve(dir, 'pages')
|
|
|
|
}
|
|
|
|
|
|
|
|
apply (compiler) {
|
2016-12-27 23:28:19 +00:00
|
|
|
compiler.plugin('compilation', (compilation) => {
|
|
|
|
compilation.plugin('optimize-assets', (assets, callback) => {
|
|
|
|
// transpile pages/_document.js and descendants,
|
|
|
|
// but don't need the bundle file
|
|
|
|
delete assets[join('bundles', 'pages', '_document.js')]
|
|
|
|
callback()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-10-23 16:42:13 +00:00
|
|
|
compiler.plugin('emit', (compilation, callback) => {
|
|
|
|
// watch the pages directory
|
2017-01-12 15:39:04 +00:00
|
|
|
compilation.contextDependencies = [
|
|
|
|
...compilation.contextDependencies,
|
|
|
|
this.dir
|
|
|
|
]
|
2016-10-23 16:42:13 +00:00
|
|
|
callback()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|