TypeError: merge is not a function
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.js');
module.exports = merge(baseConfig, {
mode: 'development',
devServer: {
open: true,
hot: true,
compress: true,
port: 3000,
// contentBase: './src'
},
devtool: 'cheap-module-eval-source-map'
})
分析原因
通过阅读webpack-merge的源码,发现该方法向外暴露了一个对象
export { merge, mergeWithCustomize, unique, customizeArray, customizeObject },如下
解决方案
通过es6提供的解构赋值,即按需加载
const {merge} = require('webpack-merge');
const baseConfig = require('./webpack.base.js');
module.exports = merge(baseConfig, {
mode: 'development',
devServer: {
open: true,
hot: true,
compress: true,
port: 3000,
// contentBase: './src'
},
devtool: 'cheap-module-eval-source-map'
})