TONY 发表于 2025-12-22 19:12:28

原创 微前端,迈向现代化前端架构的社会技术之旅


    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">文┃小夏</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">编辑┃叙言</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">后端早就靠分布式系统摆脱了单体架构的麻烦,前端却还在坑里挣扎。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">庞大的代码库拖慢效率,跨团队改个东西要反复协调,稍微动一下就怕出问题。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">作为常年跟前端架构打交道的博主,我得说,微前端的出现,根本不是单纯的技术升级,而是解决组织协作痛点的必然结果。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q0.itc.cn/q_70/images03/20251219/2fa8439d0b804a34a2c56bdf2108c4b4.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">核心认知,微前端到底是什么 </p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">很多人觉得微前端就是拆代码,其实完全搞错了,</strong>它的核心是组织工作的新方式,刚好印证了康威定律,系统设计会跟着团队协作结构走。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">以前多个团队共用一个前端项目,发布得排队协调,改个小功能都要全团队同步。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q3.itc.cn/q_70/images03/20251219/df685f1a29e34557b134120a6ed6c061.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">微前端把前端拆成一个个独立模块,每个团队负责一个,从设计到部署全自己说了算,不用等别人审批。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">有家媒体公司这么改了之后,发布协调的工作量少了一半,部署频率直接翻了十倍。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">这才是微前端的真正价值,不是技术多酷炫,而是让团队干活更顺畅,<strong style="color: black;">它和组件也不是一回事。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q7.itc.cn/q_70/images03/20251219/9db508b6eb1c4d2ca3346dd1dca5e994.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">组件是用来复用的小工具,比如一个按钮、一个输入框,<strong style="color: black;">微前端是完整的业务模块,比如整个结算流程、整个个人中心。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">组件管的是“怎么实现”,微前端管的是“谁来做、怎么交付”,两者根本不是一个层面的东西。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">适用场景,不是所有项目都需要 </p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q0.itc.cn/q_70/images03/20251219/e06ca6d065ef457ea5889baf38e78890.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">微前端再好,也不是万能的,<strong style="color: black;">如果你的项目小,就一个团队维护,用模块化单体架构完全够用,没必要瞎折腾。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">什么时候该考虑微前端呢?看看这些信号,团队越来越大,但发布速度越来越慢,改一个模块的代码,另一个模块莫名其妙出问题,新员工入职,光看懂代码就得花好几个月。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q2.itc.cn/q_70/images03/20251219/38765c80a0184f4b94202122f11f5f30.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">这些都是系统结构跟不上组织发展的表现,</strong>微前端通过让每个团队自主决策、独立交付,破解这些瓶颈。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">但如果你的团队小、业务简单,用微前端只会增加额外工作量,得不偿失。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">落地路径,从旧系统慢慢迁移 </p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q0.itc.cn/q_70/images03/20251219/31df34a5452541139583773b1080c627.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">改造现有系统,最忌讳的就是全盘重写,</strong>微前端的核心是“增量迁移”,就像藤蔓慢慢缠绕替代大树,而不是直接把树砍了。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">可以用StranglerFig模式,在边缘层设置<span style="color: green;">路由</span>规则,</strong>把结算页、个人中心这些独立路径,先迁移到新的微前端。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q8.itc.cn/q_70/images03/20251219/b8ee1e428304430ca9f7fc53ebb48e3d.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">网站其他部分还沿用旧系统,出了问题随时能切回去,风险特别低,</strong>有个零售公司就是这么做的,花14个月完成了前端迁移,期间业务没受任何影响。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">而且他们后端还是单体架构,照样实现了发布速度的提升。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">本来想,微前端得靠微服务支撑,后来发现根本不是这样,只要API接口稳定,前端完全能独立升级。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q7.itc.cn/q_70/images03/20251219/62e9b622f3e94a8fa26af240d9753707.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">首次迁移别贪大,选一个“有价值又独立”的模块下手。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">比如新功能或者要重构的模块,这样迁移工作能和业务目标对齐,不会让人觉得是瞎搞技术。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">第一个模块要覆盖从开发到监控的全流程,把遇到的问题都暴露出来,后面再迁移就有经验了。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">避坑指南,解决关键问题 </p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q8.itc.cn/q_70/images03/20251219/7a9d7ab5c45446f7b153978acac715b2.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">微前端落地最麻烦的,是路由、认证这些跨模块的问题。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">路由建议集中放在边缘节点管理,不用在每个应用里写一堆逻辑,切换版本、回滚都特别方便。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">认证也没那么复杂,只要所有微前端在同一个子域下,就能共享<span style="color: green;">cookie</span>和会话数据,不用搞复杂的跨应用通信。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q4.itc.cn/q_70/images03/20251219/acf68b3e66974f628841d5aaad7edc62.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">状态管理尽量放在每个微前端内部,实在要跨模块传递信息,用事件广播这种松耦合的方式就好。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">还有个误区是追求“零重复”,</strong>其实在<span style="color: green;">分布式系统</span>里,适当重复是好事。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">比如一个简单的表单组件,每个团队自己实现一遍,反而能减少跨团队依赖,提升交付速度。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q8.itc.cn/q_70/images03/20251219/3c29a3f9b4fd44358f2bc648442ff8d0.jpeg" style="width: 100%; margin-bottom: 20px;"></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">只有设计系统这种稳定的模块,才适合集中共享,<strong style="color: black;">微前端的核心不是技术,而是让前端架构适配团队协作方式。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">它不是要搞大跃进,而是小步快跑,在不影响业务的前提下慢慢升级。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><strong style="color: black;">对多团队、大规模的前端项目来说,它确实能破解交付瓶颈,但如果是小项目,就没必要跟风了。</strong></p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;">声明:本文内容均是根据权威材料,结合个人观点撰写的原创内容,辛苦各位看官支持,请知悉。</p>
    <p style="font-size: 18px; line-height: 40px; text-align: left; margin-bottom: 30px;"><img src="https://q9.itc.cn/q_70/images03/20251219/8b436b2787eb4ab9ba65667385de73a6.jpeg" style="width: 100%; margin-bottom: 20px;"><span style="color: green;">返回搜狐,查看更多</span></p>


页: [1]
查看完整版本: 原创 微前端,迈向现代化前端架构的社会技术之旅