Palaniichuk Dmytro
Palaniichuk Dmytro

Reputation: 3173

Remove properties in array object es6

How to remove 'modules: false' from config, I tried but, looking for a better way to do this. I mean how to better find this module property. thanks

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

Upvotes: 1

Views: 463

Answers (2)

Palaniichuk Dmytro
Palaniichuk Dmytro

Reputation: 3173

Optimization

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

Upvotes: 0

Mosè Raguzzini
Mosè Raguzzini

Reputation: 15831

Try packages like 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: {}}} 

If you want to code it by yourself remember you need a recursive function.

Upvotes: 1

Related Questions