【发布时间】:2019-02-07 07:41:01
【问题描述】:
我正在使用单个 .babelrc 配置并在 webpack.config.client.js 和 webpack.config.server.js 中与 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": {}
}
}
问题是,react-hot-loader 找到了编译服务器代码的方法。 我做了一些研究,发现 babel 7 允许 configure overrides 处理这种情况。
我尝试实现它,但“env”部分永远不会被覆盖:
{
"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": []
}
}
}
}
感谢任何帮助
【问题讨论】:
-
您是否在某处设置环境?如果是这样,如何。
-
我在 webpack 和 server 中用 dotenv 设置了 env。环境正在工作。在开发中,react-hot-loader 插件位于客户端包和服务器包中。我正在寻找如何从服务器包中删除它。
标签: javascript webpack babeljs babel-loader