require chokidar lazily; dev-mode only

This commit is contained in:
Luke Edwards
2018-01-05 00:39:17 -08:00
parent ee94f355d5
commit 0c891ba79e
3 changed files with 6 additions and 9 deletions

View File

@@ -1,5 +1,4 @@
const glob = require('glob');
const chokidar = require('chokidar');
const create_routes = require('./utils/create_routes.js');
const { src, dev } = require('./config.js');
@@ -20,7 +19,7 @@ function update() {
update();
if (dev) {
const watcher = chokidar.watch(`${src}/**/*.+(html|js|mjs)`, {
const watcher = require('chokidar').watch(`${src}/**/*.+(html|js|mjs)`, {
ignoreInitial: true,
persistent: false
});
@@ -28,4 +27,4 @@ if (dev) {
watcher.on('add', update);
watcher.on('change', update);
watcher.on('unlink', update);
}
}

View File

@@ -1,6 +1,5 @@
const fs = require('fs');
const glob = require('glob');
const chokidar = require('chokidar');
const { dev } = require('./config.js');
let templates;
@@ -65,7 +64,7 @@ function create_templates() {
create_templates();
if (dev) {
const watcher = chokidar.watch('templates/**.html', {
const watcher = require('chokidar').watch('templates/**.html', {
ignoreInitial: true,
persistent: false
});
@@ -87,4 +86,4 @@ exports.stream = (res, status, data) => {
if (template) return template.stream(res, data);
return `Missing template for status code ${status}`;
};
};

View File

@@ -1,6 +1,5 @@
const fs = require('fs');
const path = require('path');
const chokidar = require('chokidar');
const route_manager = require('../route_manager.js');
const { src, entry, dev } = require('../config.js');
@@ -70,7 +69,7 @@ function create_app() {
if (dev) {
route_manager.onchange(create_app);
const watcher = chokidar.watch(`templates/main.js`, {
const watcher = require('chokidar').watch(`templates/main.js`, {
ignoreInitial: true,
persistent: false
});
@@ -80,4 +79,4 @@ if (dev) {
watcher.on('unlink', create_app);
}
module.exports = create_app;
module.exports = create_app;