react打包压缩太慢的解决办法:1、使用“npm install hard-source-webpack-plugin”命令安装“hard-source-webpack-plugin”;2、执行“new HardSourceWebpackPlugin()”语句;3、在package.json文件的scripts中修改“max_old_space_size”即可。

本教程操作环境:Windows10系统、react18.0.0版、Dell G3电脑。
react 打包压缩太慢怎么办?
react项目太大,打包速度很慢和经常打包失败的解决方案
一、解决打包慢的问题
1、使用插件:hard-source-webpack-plugin
npm install hard-source-webpack-plugin 或 yarn add hard-source-webpack-plugin
2、在webpack的配置文件中使用
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
module.exports = {
// ......
plugins: [
new HardSourceWebpackPlugin() // <p>3、项目中使用</p><p><img src="https://img.php.cn/upload/image/210/338/225/1672277299827336.jpg?x-oss-process=image/resize,p_40" title="1672277299827336.jpg" alt="059688eba4a565b886185a3fe950f6c.jpg"></p><p>二、打包的时候经常报异常,打包不成功</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13256" title="Build React agent chat interfaces with assistant-ui"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20cf0281539.jpg" alt="Build React agent chat interfaces with assistant-ui" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13256" title="Build React agent chat interfaces with assistant-ui" class="overflowclass">Build React agent chat interfaces with assistant-ui</a>
<p class="overflowclass">使用 assistant-ui 构建具有可重用线程、运行时、消息组件和模型/提供者适配器的生产级 React 聊天界面。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13256" title="Build React agent chat interfaces with assistant-ui" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><p>1、打包时出现的问题</p><p><img src="https://img.php.cn/upload/image/378/504/176/1672277294455767.jpg?x-oss-process=image/resize,p_40" title="1672277294455767.jpg" alt="fc24e5e1c9e603fd858bccae50ab697.jpg"></p><p>打包的时候,经常报 ELIFECYCLE的异常,从网上搜这个问题,也没有搜到相关的解决方案,我仔细的研究了这个报错信息,发现nodiot-fusiondesgin-demo@0.1.0 build: `react-app-rewired --max_old_space_size=4096 build` 这一行可能会存在问题,然后我找到项目中配置该信息的地方,在package.json文件的scripts中</p><p><img src="https://img.php.cn/upload/image/875/152/919/1672277273366572.jpg?x-oss-process=image/resize,p_40" title="1672277273366572.jpg" alt="045d1ab936f0fdd2ebdbac07bf5aa0f.jpg"></p><p>2、解决方案:</p><p>把`max_old_space_size=4096` 更改为了 `max_old_space_size=8192`,更改完后,经过几次测试是可以正常打包的,不会出现该错误了</p><p>推荐学习:《<a href="https://www.php.cn/course/list/21.html" target="_blank">react视频教程</a>》</p>










