Merge pull request #64 from lukeed/lazy-chokidar

Lazily Require Chokidar
This commit is contained in:
Rich Harris
2018-01-15 10:04:37 -05:00
committed by GitHub
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,7 +1,6 @@
const fs = require('fs');
const glob = require('glob');
const chalk = require('chalk');
const chokidar = require('chokidar');
const framer = require('code-frame');
const { locate } = require('locate-character');
const { dev } = require('./config.js');
@@ -103,7 +102,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
});
@@ -125,4 +124,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;