gpt4 book ai didi

javascript - React 开发工具提示生产中的未缩小版本

转载 作者:行者123 更新时间:2023-11-29 23:38:06 24 4
gpt4 key购买 nike

我有一个正在制作中的网站,其中 Chrome 开发工具说:

This page is using an unminified build of React. 🚧

在我的构建过程中,webpack 配置正在运行 production 标志 on。我的设置是:

plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
mangle: false,
beautify: false,
sourcemap: false,
comments: false,
minimize: true,
compress: {
warnings: false,
comparisons: false
},
output: {
comments: false,
ascii_only: true
}
})
]

我正在使用 import 在我的 .js.jsx 文件中加载 React,加载带有指向 .min.js 文件的脚本标签的 HTML。与开发版本相比,代码的大小仍然有所减少。

我做错了什么?该警告的原因是什么?

我的版本:

"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.7.0"

最佳答案

经过反复试验设置mangle: true,关闭警告。

我没有在 React 文档中找到关于此的信息,但它确实有效。

React does suggest在其默认配置中运行 UglifyJsPlugin,默认情况下 mangle 设置为 true:

new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin()

关于javascript - React 开发工具提示生产中的未缩小版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45905630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com