简体   繁体   English

生产模式下的UglifyJSPlugin显示一个React开发模式警告

[英]UglifyJSPlugin in production mode shows a React development mode warning

I have an npm package that is a React component that I've built and am hosting on my private npm server. 我有一个npm软件包,它是我构建的一个React组件,并托管在我的私有npm服务器上。

I have a React web application that downloads this package and uses it on a page. 我有一个React Web应用程序,可以下载该软件包并在页面上使用它。

Both the component and the web application are being built with webpack, using the UglifyJSPlugin. 组件和Web应用程序都使用UglifyJSPlugin与webpack一起构建。

When running webpack with the production flag, I receive the following warning: 当运行带有生产标志的webpack时,收到以下警告:

warning.js:36Warning: It looks like you're using a minified copy of the development build of React. When deploying React apps to production, make sure to use the production build which skips development warnings and is faster. See [stack won't let me post urls..]fb.me/react-minification for more details.

When I remove the UglifyJSPlugin from the web application's webpack config and run webpack with the production flag, this warning doesn't appear. 当我从Web应用程序的webpack配置中删除UglifyJSPlugin并使用生产标志运行webpack时,不会出现此警告。

Any ideas on how to remove the warning when using UglifyJSPlugin in production mode? 关于在生产模式下使用UglifyJSPlugin时如何删除警告的任何想法?

As Marko said, use the DefinePlugin like this. 正如Marko所说的那样,使用DefinePlugin。

{
    entry: "src/main.js",
    output: {
        path: 'dist',
        filename: "bundle.js"
    },  plugins:[
    new webpack.DefinePlugin({
      'process.env':{
        'NODE_ENV': JSON.stringify('production')
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress:{
        warnings: true
      }
    })
  ]
 }

您应该使用DefinePlugin并将节点环境设置为生产环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM