3.在指定loader的时候不能使用exclude,否则webpack-merge不能合并,导致jsx的多个use无法完全合并从而导致重复。同时合并的时候也无法使用require.resolve,否则也是不可以合并的
exclude: function(path){
var isNpmModule=!!path.match(/node_modules/);
return isNpmModule;
},
{
"presets": [
],
"plugins": [
"react-hot-loader/babel"
]
}
如果需要如下:
{
"presets": [
["es2015", { "modules": false }],
"react",
"airbnb"
],
"plugins": [
"transform-decorators-legacy",
"transform-object-rest-spread",
"react-hot-loader/babel"
],
"env": {
"test": {
"plugins": [
"transform-decorators-legacy",
"transform-object-rest-spread",
"istanbul"
]
}
}
}
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
是不是用了这个插件就可以直接在浏览器代码中直接判断了
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"test"'
})
]
我们的两个loader即使是去掉exclude也是无法正常合并的,所以会导致两个规则被保留。最后解决方法是:wcf中不要求安装babel-loader,而是作为devDependencies,这样安装我们的webpackcc的时候不会安装babel-loader,最后我们require.resolve得到的都是同一个最高级的文件下的babel-loader。而且此时合并的时候options也会合并:
cacheDirectory: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp' } }
//即最后我们的cacheDirectory也会在options上
exclude :path.resolve("node_modules")。我们的webpackcc只是被调用而已,所以其path.resolve和我们自己配置的path.resolve其实是同一个node_modules路径,这一点一定更要注意!