简体   繁体   中英

@babel/preset-env not reading browserslist from package.config

I have created the environment variable (user and system) BROWSERSLIST_CONFIG and set it to C:\\Program Files (x86)\\Microsoft VS Code\\bin\\package.json .

However, when I run webpack and set debug to true I get empty targets:

@babel/preset-env: `DEBUG` option

Using targets:
{}

Even though my package.json has the following:

"browserslist":{
    "DEBUG": ["last 2 Firefox versions"],
    "PRODUCTION": ["> 2%", "last 2 versions", "ie >= 11"]
},

If I add the targets/browsers option directly into webpack.config it works fine but I have multiple projects and I want to share a central package.config.

Is there something missing in how I call babel-loader?

{
    test: /\.js$/,
    exclude: /node_modules/,
    use: {
        loader: 'babel-loader',
        options: {
            presets: [[nodeFolder + '@babel/preset-env', {
                targets: {
                  browsers: [
                    "last 2 Chrome versions"
                  ]
                }, "debug": true
              },
            ]],
        },
    },
},

Fixed. I added in the path to the config's directory as an option to the preset:

use: {
    loader: 'babel-loader',
    options: {
        presets: [[nodeFolder + '@babel/preset-env', { 
            "debug": true,
             "configPath": 'C:\\Program Files (x86)\\Microsoft VS Code\\bin\\'
          },
        ]],
    },
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM