|
@ -6,7 +6,7 @@ const Config = require('webpack-chain'); |
|
|
const ora = require('ora'); |
|
|
const ora = require('ora'); |
|
|
const merge = require('deepmerge'); |
|
|
const merge = require('deepmerge'); |
|
|
|
|
|
|
|
|
const normalizePath = (path, root) => isAbsolute(path) ? path : join(root, path); |
|
|
const normalizePath = (path, root) => (isAbsolute(path) ? path : join(root, path)); |
|
|
|
|
|
|
|
|
class Neutrino extends EventEmitter { |
|
|
class Neutrino extends EventEmitter { |
|
|
constructor(options = {}) { |
|
|
constructor(options = {}) { |
|
@ -16,7 +16,7 @@ class Neutrino extends EventEmitter { |
|
|
const source = normalizePath(options.source || 'src', root); |
|
|
const source = normalizePath(options.source || 'src', root); |
|
|
const output = normalizePath(options.output || 'build', root); |
|
|
const output = normalizePath(options.output || 'build', root); |
|
|
const tests = normalizePath(options.tests || 'test', root); |
|
|
const tests = normalizePath(options.tests || 'test', root); |
|
|
const node_modules = normalizePath(options.node_modules || 'node_modules', root); |
|
|
const node_modules = normalizePath(options.node_modules || 'node_modules', root); // eslint-disable-line camelcase
|
|
|
const entry = normalizePath(options.entry || 'index.js', source); |
|
|
const entry = normalizePath(options.entry || 'index.js', source); |
|
|
|
|
|
|
|
|
this.config = new Config(); |
|
|
this.config = new Config(); |
|
@ -27,6 +27,7 @@ class Neutrino extends EventEmitter { |
|
|
preset(this, options); |
|
|
preset(this, options); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* eslint-disable no-console */ |
|
|
handleErrors(err, stats) { |
|
|
handleErrors(err, stats) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
console.error(err.stack || err); |
|
|
console.error(err.stack || err); |
|
@ -47,6 +48,7 @@ class Neutrino extends EventEmitter { |
|
|
|
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
/* eslint-enable no-console */ |
|
|
|
|
|
|
|
|
getWebpackOptions() { |
|
|
getWebpackOptions() { |
|
|
return this.config.toConfig(); |
|
|
return this.config.toConfig(); |
|
@ -85,7 +87,7 @@ class Neutrino extends EventEmitter { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
devServer() { |
|
|
devServer() { |
|
|
return new Promise(resolve => { |
|
|
return new Promise((resolve) => { |
|
|
const starting = ora('Starting development server').start(); |
|
|
const starting = ora('Starting development server').start(); |
|
|
const config = this.getWebpackOptions(); |
|
|
const config = this.getWebpackOptions(); |
|
|
const protocol = config.devServer.https ? 'https' : 'http'; |
|
|
const protocol = config.devServer.https ? 'https' : 'http'; |
|
@ -111,7 +113,7 @@ class Neutrino extends EventEmitter { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
watcher() { |
|
|
watcher() { |
|
|
return new Promise(resolve => { |
|
|
return new Promise((resolve) => { |
|
|
const building = ora('Waiting for initial build to finish').start(); |
|
|
const building = ora('Waiting for initial build to finish').start(); |
|
|
const config = this.getWebpackOptions(); |
|
|
const config = this.getWebpackOptions(); |
|
|
const compiler = webpack(config); |
|
|
const compiler = webpack(config); |
|
@ -129,6 +131,7 @@ class Neutrino extends EventEmitter { |
|
|
const config = this.getWebpackOptions(); |
|
|
const config = this.getWebpackOptions(); |
|
|
const compiler = webpack(config); |
|
|
const compiler = webpack(config); |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
compiler.run((err, stats) => { |
|
|
compiler.run((err, stats) => { |
|
|
const failed = this.handleErrors(err, stats); |
|
|
const failed = this.handleErrors(err, stats); |
|
|
|
|
|
|
|
@ -136,6 +139,7 @@ class Neutrino extends EventEmitter { |
|
|
return reject(); |
|
|
return reject(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(stats.toString({ |
|
|
console.log(stats.toString({ |
|
|
colors: true, |
|
|
colors: true, |
|
|
chunks: false, |
|
|
chunks: false, |
|
|