8 changed files with 62 additions and 38 deletions
@ -1,16 +1,10 @@ |
|||
const webpack = require('webpack'); |
|||
const Future = require('fluture'); |
|||
const { webpackErrors } = require('./utils'); |
|||
const { webpackCompile, validateWebpackConfig } = require('./utils'); |
|||
|
|||
// build :: Object config -> Future (Array Error) Function
|
|||
const build = config => Future((reject, resolve) => { |
|||
const compiler = webpack(config); |
|||
|
|||
compiler.run((err, stats) => { |
|||
const errors = webpackErrors(err, stats); |
|||
|
|||
errors.length ? reject(errors) : resolve(stats); |
|||
}); |
|||
}); |
|||
const build = config => Future |
|||
.of(config) |
|||
.chain(validateWebpackConfig) |
|||
.chain(webpackCompile); |
|||
|
|||
module.exports = build; |
|||
|
@ -1,19 +1,19 @@ |
|||
const merge = require('deepmerge'); |
|||
const webpack = require('webpack'); |
|||
const DevServer = require('webpack-dev-server'); |
|||
const Future = require('fluture'); |
|||
const { createWebpackCompiler, validateWebpackConfig } = require('./utils'); |
|||
|
|||
// devServer :: Object webpackConfig -> Future () Function
|
|||
const devServer = webpackConfig => new Future((reject, resolve) => { |
|||
const config = merge({ |
|||
devServer: { host: 'localhost', port: 5000, noInfo: true } |
|||
}, webpackConfig); |
|||
const { host, port } = config.devServer; |
|||
// devServer :: Object config -> Future () Function
|
|||
const devServer = config => Future |
|||
.of(merge({ devServer: { host: 'localhost', port: 5000, noInfo: true } }, config)) |
|||
.chain(validateWebpackConfig) |
|||
.chain(createWebpackCompiler) |
|||
.chain(compiler => Future((reject, resolve) => { |
|||
const { devServer } = compiler.options; |
|||
const { host, port } = devServer; |
|||
const server = new DevServer(compiler, devServer); |
|||
|
|||
const compiler = webpack(config); |
|||
const server = new DevServer(compiler, config.devServer); |
|||
|
|||
server.listen(port, host, () => resolve(compiler)); |
|||
}); |
|||
server.listen(port, host, () => resolve(compiler)); |
|||
})); |
|||
|
|||
module.exports = devServer; |
|||
|
@ -1,16 +1,10 @@ |
|||
const webpack = require('webpack'); |
|||
const Future = require('fluture'); |
|||
const { webpackErrors } = require('./utils'); |
|||
const { createWebpackWatcher, validateWebpackConfig } = require('./utils'); |
|||
|
|||
// watch :: Object config -> Future (Array Error) ()
|
|||
const watch = config => new Future((reject, resolve) => { |
|||
const compiler = webpack(config); |
|||
|
|||
compiler.watch(config.watchOptions || {}, (err, stats) => { |
|||
const errors = webpackErrors(err, stats); |
|||
|
|||
errors.length ? reject(errors) : resolve(compiler); |
|||
}); |
|||
}); |
|||
const watch = config => Future |
|||
.of(config) |
|||
.chain(validateWebpackConfig) |
|||
.chain(createWebpackWatcher); |
|||
|
|||
module.exports = watch; |
|||
|
Loading…
Reference in new issue