javascript - 减少 React js 包大小
问题描述
在生产和在线部署中,我注意到我的应用程序包很大,因此需要很长时间才能结束加载。我正在尝试使用razzle.config.js
.
npm start
我收到此错误:
> my-razzle-app@4.0.4 start /Applications/MAMP/htdocs/xchanger-fontend-user
> razzle start
If you have issues with css make sure postcss resolves to v8.2.4.
See: https://razzlejs.org/getting-started#common-problems
CssMinimizerPlugin currently uses clean-css,
we will switch to cssnano once it supports postcss v8.2.4.
WAIT Compiling...
Bitcko-Mac:xchanger-fontend-user
到目前为止我的代码:
module.exports = {
plugins: ['scss'],
modifyWebpackConfig(opts) {
const config = opts.webpackConfig;
// add loadable webpack plugin only
// when we are building the client bundle
if (opts.env.target === "web") {
const filename = path.resolve(__dirname, "build");
// saving stats file to build folder
// without this, stats files will go into
// build/public folder
config.plugins.push(
new LoadableWebpackPlugin({
outputAsset: false,
writeToDisk: { filename },
})
);
config.plugins(new webpack.DefinePlugin({ // <-- key to reducing React's size
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}));
config.plugins.push(new webpack.optimize.AggressiveMergingPlugin());
config.plugins.push(new webpack.optimize.UglifyJsPlugin());
config.plugins.push(new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.scss$|\.html$/,
threshold: 10240,
minRatio: 0.8
}));
}
return config;
},
};
有什么建议么?
解决方案
推荐阅读
- html - CSS:仅在特定 HTML div 周围的边距?
- laravel - Laravel - 检查刀片上的路线
- java - 在 JavaFX 中登录后传递用户数据
- c++ - 映射到结构总是返回向量中的最后一个结构
- html - 从表中提取多个“td”类
- json - 如何使用 Serde 反序列化带有 True/False 的格式错误的 JSON?
- php - 正在工作的 PHP 图像函数现在正在生成所有黑色图像
- java - 如何将字符串列表映射到空列表?
- ios - AVPlayer 视频一直没有加载
- javascript - Java + Selenise 执行 java 脚本发送 api 请求