1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/build/plugins/watch-pages-plugin.js
Naoyuki Kanezawa dbecc2a701 Use dynamic entry feature of webpack (#750)
* update webpack version and use dynamic entry feature of it

* fix typo
2017-01-12 07:39:04 -08:00

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()
})
}
}