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