Reorganize and refactor build routine

This commit is contained in:
QWp6t
2016-11-06 22:31:49 -08:00
parent c1bb2b3a27
commit 8c9ba0546b
8 changed files with 107 additions and 94 deletions

View File

@@ -4,6 +4,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const browserSync = require('browser-sync');
const url = require('url');
const uniq = require('lodash/uniq');
const mergeWithConcat = require('./util/mergeWithConcat');
@@ -13,6 +14,7 @@ module.exports = class {
this.compiler = null;
this.options = mergeWithConcat({
proxyUrl: 'https://localhost:3000',
watch: [],
callback() {},
}, options);
}
@@ -27,7 +29,9 @@ module.exports = class {
compiler.plugin('compilation', () => this.watcher.notify('Rebuilding...'));
this.start();
}
// Optionally add logic for this.watcher.reload()
/* You may optionally add custom logic here to trigger either of the following */
// this.watcher.reload()
// this.watcher.reload({ stream: true })
});
}
start() {
@@ -38,13 +42,16 @@ module.exports = class {
target: this.options.target,
middleware: this.middleware(),
},
files: [],
}, this.options.browserSyncOptions);
watcherConfig.files = uniq(watcherConfig.files.concat(this.options.watch));
this.watcher.init(watcherConfig, this.options.callback.bind(this));
}
middleware() {
this.webpackDevMiddleware = webpackDevMiddleware(this.compiler, {
publicPath: this.options.publicPath,
stats: { colors: true },
stats: false,
noInfo: true,
});
this.webpackHotMiddleware = webpackHotMiddleware(this.compiler, {
log: this.watcher.notify.bind(this.watcher),