Guest User

Untitled

a guest
Jul 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. const path = require('path')
  2. const chokidar = require('chokidar')
  3. const resolve = dir => path.resolve(__dirname, '..', '..', dir)
  4. const includes = require('array-includes')
  5. const generateRoutes = require(resolve('scripts/generateRoutes'))
  6. const routeFile = resolve('src/routes/index.js')
  7.  
  8. function Plugin() {
  9. this._init = false
  10. }
  11.  
  12. Plugin.prototype.apply = function(compiler) {
  13. let watcher = chokidar.watch(resolve('src/views'), { persistent: true })
  14. watcher.on('ready', () => (this._init = true))
  15. watcher.on('add', e => this._init && generateRoutes())
  16. watcher.on('unlink', () => generateRoutes())
  17.  
  18. compiler.plugin('emit', (compilation, callback) => {
  19. callback()
  20. })
  21. }
  22.  
  23. module.exports = Plugin
Add Comment
Please, Sign In to add comment