UNPKG

653 BJavaScriptView Raw
1const Chain = require('webpack-chain')
2const merge = require('webpack-merge')
3
4module.exports = class WebpackChain extends Chain {
5 constructor({ configureWebpack, opts }) {
6 super()
7 this.configureWebpack = configureWebpack
8 this.opts = opts
9 }
10
11 toConfig() {
12 let config = super.toConfig()
13 if (typeof this.configureWebpack === 'function') {
14 config = this.configureWebpack(config, this.opts) || config
15 } else if (typeof this.configureWebpack === 'object') {
16 config = merge({}, config, this.configureWebpack)
17 }
18 return config
19 }
20
21 toString(options) {
22 return Chain.toString(this.toConfig(), options)
23 }
24}