daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Jul 13th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top