question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Babel-loader can't find production section in .babelrc

See original GitHub issue

Webpack Version: 2.5

Babel Core Version: 6.24

Babel Loader Version: 6.2.0

Please tell us about your environment: Windows 10

Behavior: I am using babel-loader with .babelrc file. When i build for production i want to add some additional options, thats why i have separate section for production. In webpack config i set BABEL_ENV = “production”. The issue is that babel-loader doesn’t actually use the “production” case in .babelrc. To test it, i commented the development section and bundle doen’t build with error on transpiling jsx. Thought for some reason babel-loader uses the default development section of .babelrc. Setting the NODE_ENV = “production” doesn’t helped, which should be the expected behavior.

{
    "env": {
        // "development": {            
        //     "presets": ["es2015", "react", "stage-2"]
        // },
        "production": {
            "presets": [["es2015", { "modules": false }], "react", "stage-2"]
        }
    }
}

webpack.config.js

rules: [
            {
                test: /\.jsx?$/,
                exclude: [/node_modules/],
                loader: "babel-loader"
            }
   //....
],
plugins: [
            new DefinePlugin({
                "process.env": {
                    "NODE_ENV": production,
                    "BABEL_ENV": production
                }
            }),
 // ...
]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
loganfsmythcommented, Apr 19, 2018

@Ky6uk The mode flag is an argument for Webpack itself and what plugins and behaviors it enables. I don’t think having it influence Babel’s configuration as the default would be reasonable. You can always do that yourself, e.g.

 module.exports = function(env) {
   // ...
   {
     loader: "babel-loader",
     options: {
       forceEnv: env.production ? "production" : "development"
     }
   }
 };

in your Webpack config if you’d like.

2reactions
danezcommented, Jun 1, 2017

You should run BABEL_ENV=production webpack or similar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Babel
You have a configuration that only applies to a single part of your project? ... Create a file called babel.config.json with the following...
Read more >
babel-loader - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
why do I have to put babel-presets inside .babelrc and ...
No, this is not the case. Specifying the presets in the webpack config will only affect webpack, everything else that uses babel (e.g....
Read more >
babel-loader - npm
cacheIdentifier : Default is a string composed by the @babel/core 's version, the babel-loader 's version, the contents of .babelrc file if it ......
Read more >
Advanced Features: Customizing Babel Config - Next.js
To start, you only need to define a .babelrc file (or babel.config.js ) at the top of your app. If such a file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found