admin管理员组文章数量:1425200
I'm using a single .babelrc
config and using it in webpack.config.client.js
and webpack.config.server.js
with babel-loader.
.babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
},
"production": {}
}
}
The problem is, react-hot-loader find it's way into piled server code. I did some research and I see that babel 7 allows to configure overrides for such case.
I tried to implement it, but the "env" part never gets overridden:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
},
"production": {}
},
"overrides": {
"include": "./src/server/index.js", // ?
"env": {
"development": {
"plugins": []
}
}
}
}
Appreciate any help
I'm using a single .babelrc
config and using it in webpack.config.client.js
and webpack.config.server.js
with babel-loader.
.babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
},
"production": {}
}
}
The problem is, react-hot-loader find it's way into piled server code. I did some research and I see that babel 7 allows to configure overrides for such case.
I tried to implement it, but the "env" part never gets overridden:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins": ["react-hot-loader/babel"]
},
"production": {}
},
"overrides": {
"include": "./src/server/index.js", // ?
"env": {
"development": {
"plugins": []
}
}
}
}
Appreciate any help
Share Improve this question edited Sep 1, 2018 at 18:09 yotke asked Sep 1, 2018 at 15:28 yotkeyotke 1,2082 gold badges13 silver badges26 bronze badges 2- Are you setting the environment somewhere? If so, how. – loganfsmyth Commented Sep 1, 2018 at 17:27
- I set env with dotenv in webpack and server. The env is working. In development, react-hot-loader plugin is in client bundle and server bundle. I'm looking how to remove it from server bundle. – yotke Commented Sep 1, 2018 at 17:31
1 Answer
Reset to default 4Babel doesn't know anything about your client/server differentiation. Your "include": "./src/server/index.js",
check would affect that single file, but not your conceptual server bundle.
Realistically, there are a bunch of ways to do this, but I'll just list a couple to start.
One would be to use env
and have 4 instead of 2 (production-client
, production-server
, development-client
, development-server
). Then you could do
"env": {
"development-client": {
"plugins": ["react-hot-loader/babel"]
},
}
Alternatively, you could set another environment variable, e.g.
cross-env NODE_ENV=development BUNDLE_NAME=server webpack --config webpack.config.server.js
and rename your config to be a .babelrc.js
file, and do
module.exports = {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"debug": false,
"modules": false,
"loose": true
}
],
"@babel/react"
],
"env": {
"development": {
"plugins":
process.env.BUNDLE_NAME === "server"
? []
: ["react-hot-loader/babel"]
},
"production": {}
},
};
本文标签:
版权声明:本文标题:javascript - How to properly override babel@7 plugins for separate webpack serverclient configurations - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745429930a2658281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论