如何从配置中删除'modules:false',我试过,但是,寻找更好的方法来做到这一点。我的意思是如何更好地找到这个模块属性。谢谢
const config = {
'presets': [
['@babel/preset-env', {
'targets': {
'browsers': ['last 1 versions', 'ie >= 11']
},
'modules': false,
}],
'@babel/react',
'@babel/stage-1'
],
'plugins': ['react-hot-loader/babel']
}
delete config.presets[0][1].modules
答案 0 :(得分:1)
尝试像omit-deep这样的软件包:
var omitDeep = require('omit-deep');
var obj = {a: 'a', b: 'b', c: {b: 'b', d: {b: 'b', f: 'f'}}};
console.log(omitDeep(obj, ['b']));
//=> {a: 'a', c: {d: {f: 'f'}}}
var obj = {a: 'a', b: 'b', c: {b: 'b', d: {b: 'b', f: 'f'}}};
console.log(omitDeep(obj, ['b', 'f']));
//=> {a: 'a', c: {d: {}}}
如果你想自己编码,记住你需要一个递归函数。
答案 1 :(得分:0)
优化
const nodeEnv = process.env.NODE_ENV || 'development'
let presetEnvConfig, plugins
if (nodeEnv === 'test'){
presetEnvConfig = {targets: {node: 'current'}}
plugins = ['istanbul']
} else {
presetEnvConfig = {
targets: {
browsers: ['last 1 versions', 'ie >= 11']
},
modules: false
}
plugins = ['react-hot-loader/babel']
}
const config = {
presets: [
['@babel/preset-env', presetEnvConfig],
'@babel/react',
'@babel/stage-1'
],
plugins,
}
module.exports = config