This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull webpack actions out of Neutrino class.
- Loading branch information
1 parent
09d78db
commit d71fee5
Showing
6 changed files
with
96 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |