Skip to content

Instantly share code, notes, and snippets.

@nick-ChenZe
Created July 13, 2018 05:39
Show Gist options
  • Save nick-ChenZe/9d2bc5196a3a1a9634980001ae73c43f to your computer and use it in GitHub Desktop.
Save nick-ChenZe/9d2bc5196a3a1a9634980001ae73c43f to your computer and use it in GitHub Desktop.
const path = require('path')
const chokidar = require('chokidar')
const resolve = dir => path.resolve(__dirname, '..', '..', dir)
const includes = require('array-includes')
const generateRoutes = require(resolve('scripts/generateRoutes'))
const routeFile = resolve('src/routes/index.js')
function Plugin() {
this._init = false
}
Plugin.prototype.apply = function(compiler) {
let watcher = chokidar.watch(resolve('src/views'), { persistent: true })
watcher.on('ready', () => (this._init = true))
watcher.on('add', e => this._init && generateRoutes())
watcher.on('unlink', () => generateRoutes())
compiler.plugin('emit', (compilation, callback) => {
callback()
})
}
module.exports = Plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment