如何在生产中禁用react-transform-hmr?

时间:2018-03-13 13:35:24

标签: node.js reactjs

我的创建反应应用程序有问题。当我运行dev版本时一切都很好。当我尝试运行构建版本时,我收到错误:

未捕获错误:locals [0]似乎不是启用了热模块替换API的module对象。您应该在Babel配置中使用env部分禁用生产中的react-transform-hmr。请参阅自述文件中的示例:https://github.com/gaearon/react-transform-hmr     at n(react-datepicker.js:4634)

我试过这个:babel.rc文件

  {
  "presets": ["es2015", "stage-0"],
  "env": {
     // only enable it when process.env.NODE_ENV is 'development' or undefined
    "development": {
      "plugins": [[
        "react-transform", {
           "transforms": [{
             "transform": "react-transform-hmr",
             // if you use React Native, pass "react-native" instead:
             "imports": ["react"],
             // this is important for Webpack HMR:
             "locals": ["module"]
           }]
           // note: you can put more transforms into array
           // this is just one of them!
        }
      ]]
    }
  }
}

我的构建命令是:

“build”:“设置NODE_ENV =生产&& react-scripts build”, 知道为什么会这样,或者我应该在哪里寻找解决方案? 感谢

0 个答案:

没有答案