我有一个 npm 包,它是我构建的 React 组件,并托管在我的私有(private) npm 服务器上。
我有一个 React Web 应用程序,它下载此包并在页面上使用它。
组件和 Web 应用程序都是使用 Webpack 和 UglifyJSPlugin 构建的。
当使用生产标志运行 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.
当我从 Web 应用程序的 webpack 配置中删除 UglifyJSPlugin 并使用生产标志运行 webpack 时,不会出现此警告。
关于如何在生产模式下使用 UglifyJSPlugin 时删除警告有什么想法吗?
最佳答案
正如 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
}
})
]
}
关于javascript - 生产模式下的 UglifyJSPlugin 显示 React 开发模式警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39576487/