1
1
mirror of https://github.com/c8r/x0.git synced 2024-09-11 21:57:26 +03:00

Add prototype for custom configuration

This commit is contained in:
Brent Jackson 2018-02-11 12:18:17 -05:00
parent 5098b21feb
commit fb35ce31c9
4 changed files with 26 additions and 3 deletions

View File

@ -27,6 +27,8 @@ const cli = meow(`
-o --open Open dev server in default browser
-c --config Pass a custom weback config to merge with the default config
--proxy Proxy requests to another server (only for dev)
--proxy-path Path to proxy, default: /api
@ -37,6 +39,7 @@ const cli = meow(`
s: 'static',
p: 'port',
o: 'open',
c: 'config',
h: 'help',
v: 'version',
}

View File

@ -17,6 +17,7 @@ require('babel-register')({
const path = require('path')
const webpack = require('webpack')
const DevServer = require('webpack-dev-server')
const merge = require('webpack-merge')
const config = require('./config')
const devOptions = {
@ -91,5 +92,14 @@ module.exports = (filename, options = {}) => {
'webpack/hot/only-dev-server'
)
return start(filename, options, config)
let mergedConfig = config
if (options.config) {
const userConfig = require(
path.join(process.cwd(), options.config)
)
mergedConfig = merge(config, userConfig)
}
return start(filename, options, mergedConfig)
}

View File

@ -2,6 +2,7 @@ const path = require('path')
const webpack = require('webpack')
const MinifyPlugin = require('babel-minify-webpack-plugin')
const { ReactLoadablePlugin } = require('react-loadable/webpack')
const merge = require('webpack-merge')
const config = {
// mode: 'production',
@ -85,7 +86,15 @@ module.exports = (filename, options = {}) => {
})
)
const compiler = webpack(config)
let mergedConfig = config
if (options.config) {
const userConfig = require(
path.join(process.cwd(), options.config)
)
mergedConfig = merge(config, userConfig)
}
const compiler = webpack(mergedConfig)
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {

View File

@ -43,7 +43,8 @@
"read-pkg-up": "^2.0.0",
"update-notifier": "^2.2.0",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.1"
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.1"
},
"devDependencies": {
"ava": "^0.24.0",