mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
dbecc2a701
* update webpack version and use dynamic entry feature of it * fix typo
29 lines
718 B
JavaScript
29 lines
718 B
JavaScript
import { resolve, join } from 'path'
|
|
|
|
export default class WatchPagesPlugin {
|
|
constructor (dir) {
|
|
this.dir = resolve(dir, 'pages')
|
|
}
|
|
|
|
apply (compiler) {
|
|
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()
|
|
})
|
|
})
|
|
|
|
compiler.plugin('emit', (compilation, callback) => {
|
|
// watch the pages directory
|
|
compilation.contextDependencies = [
|
|
...compilation.contextDependencies,
|
|
this.dir
|
|
]
|
|
callback()
|
|
})
|
|
}
|
|
}
|
|
|