Jarid Margolin
8 years ago
6 changed files with 96 additions and 159 deletions
@ -0,0 +1,10 @@ |
|||
const webpack = require('webpack'); |
|||
const { handle, logErrors, logStats } = require('./utils'); |
|||
|
|||
module.exports = config => new Promise((resolve, reject) => { |
|||
const compiler = webpack(config); |
|||
|
|||
compiler.run(handle((errors, stats) => ( |
|||
errors.length ? reject(logErrors(errors)) : resolve(logStats(stats)) |
|||
))); |
|||
}); |
@ -0,0 +1,28 @@ |
|||
const ora = require('ora'); |
|||
const merge = require('deepmerge'); |
|||
const webpack = require('webpack'); |
|||
const DevServer = require('webpack-dev-server'); |
|||
|
|||
module.exports = _config => new Promise((resolve) => { |
|||
const defaultDevServer = { host: 'localhost', port: 5000, noInfo: true }; |
|||
const config = merge({ deverServer: defaultDevServer }, _config); |
|||
const protocol = config.devServer.https ? 'https' : 'http'; |
|||
const { host, port } = config.devServer; |
|||
|
|||
const starting = ora('Starting development server').start(); |
|||
const compiler = webpack(config); |
|||
const server = new DevServer(compiler, config.devServer); |
|||
const building = ora('Waiting for initial build to finish').start(); |
|||
|
|||
server.listen(port, host, () => { |
|||
starting.succeed(`Development server running on: ${protocol}://${host}:${port}`); |
|||
|
|||
compiler.plugin('done', () => building.succeed('Build completed')); |
|||
compiler.plugin('compile', () => { |
|||
building.text = 'Source changed, re-compiling'; |
|||
building.start(); |
|||
}); |
|||
}); |
|||
|
|||
process.on('SIGINT', resolve); |
|||
}); |
@ -0,0 +1,22 @@ |
|||
module.exports.handle = fn => (err, stats) => fn(err ? [err] : stats.toJson().errors, stats); |
|||
|
|||
module.exports.logStats = (stats) => { |
|||
console.log(stats.toString({ |
|||
colors: true, |
|||
chunks: false, |
|||
children: false |
|||
})); |
|||
|
|||
return stats; |
|||
}; |
|||
|
|||
module.exports.logErrors = (errors) => { |
|||
errors.forEach((err) => { |
|||
console.error(err.stack || err); |
|||
if (err.details) { |
|||
console.error(err.details); |
|||
} |
|||
}); |
|||
|
|||
return errors; |
|||
}; |
@ -0,0 +1,15 @@ |
|||
const webpack = require('webpack'); |
|||
const ora = require('ora'); |
|||
const { handle, logErrors } = require('./utils'); |
|||
|
|||
module.exports = config => new Promise((resolve) => { |
|||
const compiler = webpack(config); |
|||
const building = ora('Waiting for initial build to finish').start(); |
|||
|
|||
const watcher = compiler.watch(config.watchOptions || {}, handle((errors) => { |
|||
building.succeed('Build completed'); |
|||
logErrors(errors); |
|||
})); |
|||
|
|||
process.on('SIGINT', () => watcher.close(resolve)); |
|||
}); |
Loading…
Reference in new issue