Babel-loader can't find production section in .babelrc
See original GitHub issueWebpack 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:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.in your Webpack config if you’d like.
You should run
BABEL_ENV=production webpack
or similar.