5ep9lzv 发表于 2024-10-10 08:14:05

MicroApp 1.0 正式发布


    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-axegupay5k/1610786b55944b38a4d5631fe6c380b4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=M6G3pHB%2FyeXSNLq3o3PaPIjQkmE%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">大众</span>好,我是Echa。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">好<span style="color: black;">信息</span>,2023年10月份京东前端<span style="color: black;">研发</span>团队对外宣布MicroApp 1.0 正式发布</span></strong>。<span style="color: black;">此<span style="color: black;">信息</span>一出,又在Web <span style="color: black;">研发</span>者各大论坛讨论的沸沸扬扬,说前段时间</span>字节跳动 <span style="color: black;">ByteDance Web Infra 团队才对外宣布 <a style="color: black;">Rspress 1.0 正式发布</a>,这京东前端<span style="color: black;">研发</span>团队又接着发布微前端</span>MicroApp。有的人说<span style="color: black;">她们</span>是商量好的;有的人说各自在重复造轮子,各自卷;<span style="color: black;">有些人说各自为了完成KPI;粉丝们你们怎么看呢?欢迎在评论下说出自己的看法。</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/7df8a5ebaadd4c6ea2d75863a552ca7f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=gQZbKFje%2BS%2F%2BcpjLyZCgIflHRdU%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MicroApp v1.0.0 -alpha.6版本</p>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">从去年</span>M<span style="color: black;">icroApp v1.0.0 -alpha.6版本(</span>2022-08-19<span style="color: black;">),历经来多少个日日夜夜。一路迭代更新到<span style="color: black;">此刻</span></span><strong style="color: blue;"><span style="color: black;">MicroApp </span></strong><span style="color: black;">1.0版本,</span><strong style="color: blue;"><span style="color: black;">京东前端<span style="color: black;">研发</span>团队</span></strong><span style="color: black;">真心<span style="color: black;">不易</span>,<span style="color: black;">博主</span>这一路来看着<span style="color: black;">成长</span>的。你们这种<span style="color: black;">研发</span>精神,非常值得<span style="color: black;">咱们</span>程序员学习,<span style="color: black;">博主</span>给你们点赞。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">借此机会,<span style="color: black;">博主</span>先给<span style="color: black;">大众</span><span style="color: black;">仔细</span>介绍一下<strong style="color: blue;"><span style="color: black;">MicroApp 到底是什么,能做什么,有<span style="color: black;">那些</span>优点等等</span></strong>,<span style="color: black;">仅有</span>彻底<span style="color: black;">认识</span>了<strong style="color: blue;">MicroApp</strong><span style="color: black;">,<span style="color: black;">才可</span>说出自己观点。<span style="color: black;">期盼</span>对<span style="color: black;">大众</span>有所<span style="color: black;">帮忙</span>,多<span style="color: black;">认识</span>,多学点有益无害,说不定哪天团队<span style="color: black;">研发</span>项目中就用上,你说是不是?下面<span style="color: black;">博主</span>给<span style="color: black;">大众</span>一一介绍上面的问题。</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">全文大纲</h1>MicroApp 介绍MicroApp 项目背景MicroApp <span style="color: black;">优良</span>有<span style="color: black;">那些</span>?MicroApp 扩展性<span style="color: black;">怎样</span>呢?MicroApp <span style="color: black;">研发</span>调试工具介绍:Micro-App-DevTools<span style="color: black;">怎样</span><span style="color: black;">安排</span>搭建自己的 MicroApp呢?<span style="color: black;">怎样</span>将MicroApp 0.x 版本升级到 1.0 版本呢?<h1 style="color: black; text-align: left; margin-bottom: 10px;">MicroApp 介绍</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">传送门:</p>https://micro-zoe.github.io/micro-app/

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Github:https://github.com/micro-zoe/micro-app</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/bb3525836af84328bb6c2e12f187151a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=Nafa6RNPFy9KIVIxF%2BGUSJja%2BkY%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MicroApp 官网</p>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">micro-app是京东零售推出的一款微前端框架,它基于类WebComponent进行渲染,从组件化的思维实现微前端,旨在降低上手难度、<span style="color: black;">提高</span>工作效率。它是<span style="color: black;">日前</span>接入微前端成本最低的框架,并且<span style="color: black;">供给</span>了JS沙箱、样式隔离、元素隔离、预加载、虚拟路由系统、插件系统、数据通信等一系列完善的功能。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">micro-app与技术栈无关,对前端框架<span style="color: black;">无</span>限制,任何框架都<span style="color: black;">能够</span><span style="color: black;">做为</span>基座应用嵌入任何类型的子应用。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">微前端的概念<span style="color: black;">是由于</span><span style="color: black;">思特沃克软件技术(北京)有限<span style="color: black;">机构</span> </span>ThoughtWorks 在2016年提出的,它借鉴了微服务的架构理念,核心在于将一个庞大的前端应用拆分成多个独立灵活的小型模块应用,<span style="color: black;">每一个</span>应用都<span style="color: black;">能够</span>独立<span style="color: black;">研发</span>、独立运行、独立<span style="color: black;">安排</span>,再将这些小型应用融合为一个完整的应用,<span style="color: black;">或</span>将<span style="color: black;">本来</span>运行已久、<span style="color: black;">无</span><span style="color: black;">相关</span>的几个应用融合为一个应用。微前端既<span style="color: black;">能够</span>将多个项目融合为一,又<span style="color: black;">能够</span>减少项目之间的耦合,<span style="color: black;">提高</span>项目扩展性,相比一整块的前端模块仓库,微前端架构下的前端模块仓库倾向于更小更灵活。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">此时此刻, <strong style="color: blue;"><span style="color: black;">京东前端<span style="color: black;">研发</span>团队<span style="color: black;">开发</span></span>MicroApp</strong> 诞生。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">它<span style="color: black;">重点</span><span style="color: black;">处理</span>了两个问题:</p>1、随着项目迭代应用越来越庞大,难以<span style="color: black;">守护</span>。2、跨团队或跨<span style="color: black;">分部</span>协作<span style="color: black;">研发</span>项目<span style="color: black;">引起</span>效率低下的问题。<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">千言万语介绍 <strong style="color: blue;">MicroApp,不如一张图介绍更让粉丝们理解深刻,<span style="color: black;">详细</span>如下图:</strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/ca3f84c7e995408ba5102db1896b05e7~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=071%2BN60sX60p1J6OXFBsOy3ZN%2Bs%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">MicroApp 项目背景</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在micro-app之前,业内<span style="color: black;">已然</span>有<span style="color: black;">有些</span>开源的微前端框架,比较流行的有2个:<strong style="color: blue;"><span style="color: black;">single-spa和qiankun。不<span style="color: black;">晓得</span>粉丝们有<span style="color: black;">无</span>用过?</span></strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/5b04787aac9d4ae3ae5cf979ac86732c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=kGMlEuynh9j5jnU07xdZspPgYgw%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">single-spa</p>
    </div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/7d51ed10f1884108a211eee08dcde01c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=fijeiNIJG0%2Ft0ho8CV0xjFrRUCQ%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">qiankun</p>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">single-spa是<span style="color: black;">经过</span>监听 url change 事件,在路由变化时匹配到渲染的子应用并进行渲染,这个思路<span style="color: black;">亦</span>是<span style="color: black;">日前</span>实现微前端的主流方式。<span style="color: black;">同期</span>single-spa<span style="color: black;">需求</span>子应用修改渲染<span style="color: black;">规律</span>并暴露出三个<span style="color: black;">办法</span>:bootstrap、mount、unmount,分别对应初始化、渲染和卸载,这<span style="color: black;">亦</span><span style="color: black;">引起</span>子应用需要对入口文件进行修改。<span style="color: black;">由于</span>qiankun是基于single-spa进行封装,<span style="color: black;">因此</span>这些特点<span style="color: black;">亦</span>被qiankun继承下来,并且需要对webpack配置进行<span style="color: black;">有些</span>修改。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">micro-app</strong>并没有沿袭single-spa的思路,而是借鉴了WebComponent的思想,<span style="color: black;">经过</span>CustomElement结合自定义的ShadowDom,将微前端封装成一个类WebComponent组件,从而实现微前端的组件化渲染。并且<span style="color: black;">因为</span>自定义ShadowDom的隔离特性,micro-app不需要像single-spa和qiankun<span style="color: black;">同样</span><span style="color: black;">需求</span>子应用修改渲染<span style="color: black;">规律</span>并暴露出<span style="color: black;">办法</span>,<span style="color: black;">亦</span>不需要修改webpack配置,是<span style="color: black;">日前</span>市面上接入微前端成本最低的<span style="color: black;">方法</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">描述了这么多,老规矩,直接上图会<span style="color: black;">更易</span>理解,<span style="color: black;">详细</span>如下图:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/fd783770347d4b699dd00ed26f7ecfa2~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=y036TCO8eT9DUkv0vo14M2dJsGk%3D" style="width: 50%; margin-bottom: 20px;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">micro-app 架构图</p>
    </div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">MicroApp <span style="color: black;">优良</span>有<span style="color: black;">那些</span>?</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">运用</span>简单</strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/cfc8e6815252435dad23cc812e6af761~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=evfiDGYgKuPh%2BHTNe5OWZVgdkP0%3D" style="width: 50%; margin-bottom: 20px;"></div><span style="color: black;">&lt;<span style="color: black;">micro-app</span> <span style="color: black;">name</span>=<span style="color: black;">my-app’ url=</span>//<span style="color: black;">localhost:3000</span>/&gt;</span><span style="color: black;">&lt;/<span style="color: black;">micro-app</span>&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">官方将所有功能都封装到一个类WebComponent组件中,从而实<span style="color: black;">此刻</span>基座应用中嵌入一行代码<span style="color: black;">就可</span>渲染一个微前端应用。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/f5f2d588a4a14e05be4a8fafc528ce07~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=f012urTc0ybvshLEZoXVUeQ3dNA%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">功能强大</strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/b7a23a18a2a9452981a004f6a7144547~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=S3kG7MUiZhs9Ba%2BME13sVpeaDV8%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">micro-app<span style="color: black;">供给</span>了js沙箱、样式隔离、元素隔离、路由隔离、预加载、数据通信等一系列完善的功能。</p>js沙箱 介绍<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">官方<span style="color: black;">运用</span>Proxy拦截了用户全局操作的<span style="color: black;">行径</span>,防止对window的<span style="color: black;">拜访</span>和修改,避免全局变量污染。micro-app中的<span style="color: black;">每一个</span>子应用都运行在沙箱环境,以获取相对纯净的运行空间。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">沙箱是默认开启的,正常<span style="color: black;">状况</span>下不<span style="color: black;">意见</span>关闭,以避免<span style="color: black;">显现</span>不可预知的问题。</p>样式隔离<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MicroApp的样式隔离是默认开启的,开启后会以&lt;micro-app&gt;标签<span style="color: black;">做为</span>样式<span style="color: black;">功效</span>域,利用标签的name属性为<span style="color: black;">每一个</span>样式添加前缀,将子应用的样式影响禁锢在当前标签区域。</p><span style="color: black;">.test</span> {
    <span style="color: black;">color</span>: red;
    }

    <span style="color: black;">/* 转换为 */</span>
    <span style="color: black;">micro-app</span><span style="color: black;"></span> <span style="color: black;">.test</span> {
    <span style="color: black;">color</span>: red;
    }<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">但主应用的样式依然会对子应用产生影响,<span style="color: black;">倘若</span><span style="color: black;">出现</span>样式污染,<span style="color: black;">举荐</span><span style="color: black;">经过</span>约定前缀或CSS Modules方式<span style="color: black;">处理</span>。</p>元素隔离<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">元素隔离的概念来自ShadowDom,即ShadowDom中的元素<span style="color: black;">能够</span>和<span style="color: black;">外边</span>的元素重复但不会冲突,micro-app模拟实现了类似ShadowDom的功能,元素不会逃离&lt;micro-app&gt;元素边界,子应用只能对<span style="color: black;">自己</span>的元素进行增、删、改、查的操作。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">举个栗子 :</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">主应用和子应用都有一个元素&lt;div id=root&gt;&lt;/div&gt;,此时子应用<span style="color: black;">经过</span>document.querySelector(#root)获取到的是自己内部的#root元素,而不是主应用的。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">主应用<span style="color: black;">能够</span>获取子应用的元素吗?</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">能够</span>的!</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这一点和ShadowDom<span style="color: black;">区别</span>,在微前端下主应用<span style="color: black;">持有</span><span style="color: black;">统一</span>全局的<span style="color: black;">功效</span>,<span style="color: black;">因此</span><span style="color: black;">咱们</span><span style="color: black;">无</span>对主应用操作子应用元素的<span style="color: black;">行径</span>进行限制。</p>路由隔离<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">MicroApp<span style="color: black;">经过</span>自定义location和history,实现了一套虚拟路由系统,子应用运行在这套虚拟路由系统中,和主应用的路由进行隔离,避免相互影响。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">子应用的路由信息会<span style="color: black;">做为</span>query参数同步到浏览器地址上,如下:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/11b01bc1ec84453e965c3d5b7f6916f6~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=V9sVtZKAzLTEE%2ByfoLxS6NGAzgg%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">虚拟路由系统还<span style="color: black;">供给</span>了丰富的功能,<span style="color: black;">帮忙</span>用户<span style="color: black;">提高</span><span style="color: black;">研发</span>效率和<span style="color: black;">运用</span>体验。</p>预加载<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">预加载<span style="color: black;">指的是</span>在子应用尚未渲染时提前加载静态资源,从而<span style="color: black;">提高</span>子应用的首次渲染速度。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">为了不影响主应用的性能,预加载会在浏览器空闲时间执行。</p>数据通信<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">micro-app<span style="color: black;">供给</span>了一套灵活的数据通信机制,方便主应用和子应用之间的数据传输。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">主应用和子应用之间的通信是绑定的,主应用只能向指定的子应用发送数据,子应用只能向主应用发送数据,这种方式<span style="color: black;">能够</span>有效的避免数据污染,防止多个子应用之间相互影响。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">同期</span><span style="color: black;">咱们</span><span style="color: black;">亦</span><span style="color: black;">供给</span>了全局通信,方便跨应用之间的数据通信。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">兼容所有框架</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">为了<span style="color: black;">保准</span>各个业务之间独立<span style="color: black;">研发</span>、独立<span style="color: black;">安排</span>的能力,micro-app做了<span style="color: black;">许多</span>兼容,在任何前端框架中都<span style="color: black;">能够</span>正常运行。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">MicroApp 扩展性<span style="color: black;">怎样</span>呢?</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">官方从功能的<span style="color: black;">方向</span>介绍<span style="color: black;">怎样</span>接入微前端,这<span style="color: black;">引起</span>整体的<span style="color: black;">规律</span>不连贯。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在手把手系列中,<span style="color: black;">咱们</span>会侧重于前端框架本身,<span style="color: black;">仔细</span>介绍它们<span style="color: black;">做为</span>主应用和子应用<span style="color: black;">怎样</span>接入微前端。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>列举比较流行的前端框架,指出各框架的<span style="color: black;">重视</span>事项,规避<span style="color: black;">各样</span>可能<span style="color: black;">显现</span>的问题。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">日前</span>有:</span></strong></p><span style="color: black;">react</span><span style="color: black;">vue</span><span style="color: black;">vite</span><span style="color: black;">angular</span><span style="color: black;">nextjs</span><span style="color: black;">nuxtjs</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以上框架<span style="color: black;">能够</span>任意组合,换句话说任何一个框架都<span style="color: black;">能够</span><span style="color: black;">做为</span>主应用嵌入其它类型的子应用,任何一个框架<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">做为</span>子应用被其它框架嵌入,<span style="color: black;">包含</span>上面<span style="color: black;">无</span>列举出的其它库,如 svelte、umi ...</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">MicroApp <span style="color: black;">研发</span>调试工具介绍:Micro-App-DevTools</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Github:https://github.com/micro-zoe/micro-app-chrome-plugin</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/76aac523b1db447abdaa5b210e51200f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=i7mSc0RQsd%2BA2dS0oRYuHNt7%2FIE%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Micro-App-DevTools是基于京东零售推出的一款为micro-app框架而<span style="color: black;">研发</span>的chrome插件,旨在方便<span style="color: black;">研发</span>者对微前端进行数据查看以及调试,<span style="color: black;">提高</span>工作效率。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在chrome中输入chrome://extensions打开扩展程序,将已下载的插件拖入<span style="color: black;">就可</span></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/8da8583098f948d2a4b5f6f328d5161c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=tfpzc11hMFmUuDGbpncv6nTLEyQ%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">Micro-App-DevTools 功能</strong></p><strong style="color: blue;">Environment环境</strong>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">可查看Micro app的Environment环境如下:</p><span style="color: black;">__MICRO_APP_ENVIRONMENT__</span>: <span style="color: black;">判断应用<span style="color: black;">是不是</span>在微前端环境中</span>
    <span style="color: black;">__MICRO_APP_VERSION__</span>: <span style="color: black;">微前端版本号</span>
    <span style="color: black;">__MICRO_APP_NAME__</span>: <span style="color: black;">应用名<span style="color: black;">叫作</span></span>
    <span style="color: black;">__MICRO_APP_PUBLIC_PATH__</span>: <span style="color: black;">子应用的静态资源前缀</span>
    <span style="color: black;">__MICRO_APP_BASE_ROUTE__</span>: <span style="color: black;">子应用的<span style="color: black;">基本</span>路由</span>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/901d2f3611014cfa9f6a41be0e32487d~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=5sedk%2Fh3%2B6UKU5VOZu7qtrQXynw%3D" style="width: 50%; margin-bottom: 20px;"></div><strong style="color: blue;">Communicate通讯</strong>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">查看父子应用通讯 数据通信面板</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">功能<span style="color: black;">1、</span>获取父应用数据</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击按钮获取当前被嵌入页面基座应用的JSON格式数据</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/6a8ccacbb76849e493340d82dafaaee9~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=f5q9N4Vs7whx0Z0IHJL%2FI60RpX4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">功能<span style="color: black;">2、</span>子应用<span style="color: black;">研发</span>环境模拟</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击按钮<span style="color: black;">转</span>至功能一中子应用<span style="color: black;">研发</span>环境模拟页面,此处模仿内嵌子应用,<span style="color: black;">运用</span>说明如下所示:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在子应用<span style="color: black;">研发</span>环境模拟页面中输入子页面URL等信息</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">a、子页面URL:此处输入被基座应用嵌入的子应用链接</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">b、父应用数据:此处输入JSON格式的父应用需要传给子应用的数据</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">c、子应用嵌入代码:此处<span style="color: black;">表示</span>子应用嵌入的代码</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以上即完成微前端的嵌入,效果如下:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/8400680e2e5f4e18827eca1db98eb612~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=t69t0Lvh%2Fs%2FMm9d0UPq6zwNKhVs%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">快捷打开方式一</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击右上角图标<span style="color: black;">显现</span>目录,<span style="color: black;">选取</span>"打开子应用<span style="color: black;">研发</span>环境模拟"</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/08c92d4e667545feaaeb83074e79a8c1~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=Ng%2FG7jrDdEyNXViqf2Ymheg1grg%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">快捷打开方式二</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击鼠标右键,<span style="color: black;">选取</span>micro-app下,二级菜单点子应用<span style="color: black;">研发</span>环境模拟</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/ed4e8900309d47d09b111bfb62a7df4f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=x5TByGTGrjpZLzI6c2ttqjgzyAk%3D" style="width: 50%; margin-bottom: 20px;"></div><strong style="color: blue;">View子应用视图</strong>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">查看子应用<span style="color: black;">关联</span>视图信息</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击按钮<span style="color: black;">就可</span>获取当前被嵌入页面基座应用的视图</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/7157571d6384421bbc04e0a0a2282432~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=RXpFaP%2FXBKFHEcWHLqhDw9zXhW8%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">快捷打开方式</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击鼠标右键,<span style="color: black;">选取</span>micro-app下,二级菜单点击查看子应用范围</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/eeeb88ffa32e4d3e928bd4e76442fcbc~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=SyF5UdPBIDtnTU4A128mSnRtuGA%3D" style="width: 50%; margin-bottom: 20px;"></div><strong style="color: blue;">Route路由</strong>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/b41b8dc5bbbd492b8d76a9001de514b1~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=U3PPrBEGCaKSc%2BDY5tPIHvZQWt4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">功能<span style="color: black;">1、</span>获取子应用路由</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击查看子应用URL按钮<span style="color: black;">就可</span>获取当前页面下所有子应用的路由<span style="color: black;">位置</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">功能<span style="color: black;">2、</span>复制及打开子应用路由链接</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击复制按钮复制子应用路由,点击打开按钮直接在浏览器打开子应用链接<span style="color: black;">位置</span></p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">怎样</span><span style="color: black;">安排</span>搭建自己的 MicroApp呢?</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>分别列出主应用和子应用需要进行的修改,<span style="color: black;">详细</span>介绍micro-app的<span style="color: black;">运用</span>方式。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">主应用</strong></p>安装依赖 <span style="color: black;">npm</span> i @micro-zoe/micro-app --save初始化<span style="color: black;">micro-app</span><span style="color: black;">// index.js</span>
    <span style="color: black;">import</span>microApp<span style="color: black;">from</span> <span style="color: black;">@micro-zoe/micro-app</span>

    microApp.start()<span style="color: black;">嵌入子应用</span><span style="color: black;">// React</span>

    <span style="color: black;">export</span> <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">MyPage</span> () </span>{
    <span style="color: black;">return</span> (
    <span style="color: black;"><span style="color: black;">&lt;<span style="color: black;">div</span>&gt;</span>
      <span style="color: black;">&lt;<span style="color: black;">h1</span>&gt;</span>子应用<span style="color: black;">&lt;/<span style="color: black;">h1</span>&gt;</span>
      // name:应用名<span style="color: black;">叫作</span>, url:应用<span style="color: black;">位置</span>
      <span style="color: black;">&lt;<span style="color: black;">micro-app</span> <span style="color: black;">name</span>=<span style="color: black;">my-app</span> <span style="color: black;">url</span>=<span style="color: black;">http://localhost:3000/</span>&gt;</span><span style="color: black;">&lt;/<span style="color: black;">micro-app</span>&gt;</span>
      <span style="color: black;">&lt;/<span style="color: black;">div</span>&gt;</span></span>
    )
    }<span style="color: black;">//Vue</span>
    &lt;template&gt;
    <span style="color: black;"><span style="color: black;">&lt;<span style="color: black;">div</span>&gt;</span>
      <span style="color: black;">&lt;<span style="color: black;">h1</span>&gt;</span>子应用<span style="color: black;">&lt;/<span style="color: black;">h1</span>&gt;</span>
      <span style="color: black;">&lt;!-- name:应用名<span style="color: black;">叫作</span>, url:应用<span style="color: black;">位置</span> --&gt;</span>
      <span style="color: black;">&lt;<span style="color: black;">micro-app</span> <span style="color: black;">name</span>=<span style="color: black;">my-app</span> <span style="color: black;">url</span>=<span style="color: black;">http://localhost:3000/</span>&gt;</span><span style="color: black;">&lt;/<span style="color: black;">micro-app</span>&gt;</span>
      <span style="color: black;">&lt;/<span style="color: black;">div</span>&gt;</span></span>
    <span style="color: black;"><span style="color: black;">&lt;/<span style="color: black;">template</span>&gt;</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">子应用</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、在webpack-dev-server的headers中设置跨域支持。</p><span style="color: black;">devServer</span>: {
    <span style="color: black;">headers</span>: {
    <span style="color: black;">Access-Control-Allow-Origin</span>: <span style="color: black;">*</span>,
    }
    },<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">完成以上<span style="color: black;">过程</span>即完成微前端的接入。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">怎样</span>将MicroApp 0.x 版本升级到 1.0 版本呢?</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">从0.x版本迁移到1.0只针<span style="color: black;">针对</span>旧项目</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">迁移<span style="color: black;">过程</span></strong></p><strong style="color: blue;"><span style="color: black;">安装最新版本</span></strong><span style="color: black;">npm</span> i @micro-zoe/micro-app@latest --save<strong style="color: blue;"><span style="color: black;">在start中<span style="color: black;">增多</span>配置</span></strong><span style="color: black;">// index.js</span>
    <span style="color: black;">import</span> microApp <span style="color: black;">from</span> <span style="color: black;">@micro-zoe/micro-app</span>

    microApp.start({
    <span style="color: black;">disable-memory-router</span>: <span style="color: black;">true</span>, <span style="color: black;">// 关闭虚拟路由系统</span>
    <span style="color: black;">disable-patch-request</span>: <span style="color: black;">true</span>, <span style="color: black;">// 关闭对子应用请求的拦截</span>
    })<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">vite迁移</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这儿</span>只针对子应用是vite的<span style="color: black;">状况</span>,基座为vite不需要特殊处理。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">过程</span>1:删除子应用vite.config.js中的配置</span></strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/43d3dd67b6414fb2a0d5cbee69378e5c~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=7GnNNlZjDLgaPF2cSTwCz4m6Wp4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">过程</span>2:开启iframe沙箱</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">去除之前的两个配置项:inline、disableSandbox,<span style="color: black;">而后</span>开启iframe沙箱。</p><span style="color: black;">&lt;<span style="color: black;">micro-app</span> <span style="color: black;">name</span>=<span style="color: black;">名<span style="color: black;">叫作</span></span> <span style="color: black;">url</span>=<span style="color: black;"><span style="color: black;">位置</span></span> <span style="color: black;">iframe</span>&gt;</span><span style="color: black;">&lt;/<span style="color: black;">micro-app</span>&gt;</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">过程</span>3:删除基座中的自定义插件</strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/5de0105349d84a56b19d53242eb7bf9b~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=QnLMLux4PuzkejYnjmmYjDyJAww%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">过程</span>4:删除手动注册的通信对象</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">删除手动注册的通信对象,改用默认的通信方式进行数据通信</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/5a2ccb8898e14f34a3b52a3bd4be375e~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1728788176&amp;x-signature=cvnIUkxT98uE2XKqXj64X9dgIl0%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">最后</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">粉丝们,</span><strong style="color: blue;"><span style="color: black;">MicroApp 1.0 </span></strong><span style="color: black;">版本介绍有什么想法呢?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">欢迎在评论区分享讨论。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">一台电脑,一个键盘,尽情挥洒智慧的人生;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">几行数字,几个字母,认真编写生活的美好;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">一 个灵感,一段程序,推动科技进步,促进社会发展。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">创作<span style="color: black;">很难</span>,<span style="color: black;">爱好</span>的老铁们加个关注,点个赞,打个赏,后面会不<span style="color: black;">定时</span>更新干货和技术<span style="color: black;">关联</span>的<span style="color: black;">新闻</span>,速速<span style="color: black;">保藏</span>,谢谢!你们的一个小小举动<span style="color: black;">便是</span>对<span style="color: black;">博主</span>的认可,<span style="color: black;">更加是</span>创作的动力。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">创作<span style="color: black;">文案</span>的初心是:沉淀、分享和利他。既想写给<span style="color: black;">此刻</span>的你,<span style="color: black;">亦</span>想贪心写给 10 年、20 年后的工程师们,<span style="color: black;">此刻</span>的你站在浪潮之巅,面对魔幻的互联网世界,很容易把一条河流看成整片大海。<span style="color: black;">将来</span>的读者<span style="color: black;">已然</span><span style="color: black;">晓得</span>了这段技术的发展历史,但难免会忽略<span style="color: black;">有些</span>细节。<span style="color: black;">倘若</span><span style="color: black;">将来</span>的工程师们真的创造出了时间旅行<span style="color: black;">设备</span>,<span style="color: black;">能够</span>让你回到<span style="color: black;">此刻</span>。<span style="color: black;">那样</span><span style="color: black;">博主</span>的创作<span style="color: black;">便是</span>你和当年工程师们的接头暗号,你能感知到<span style="color: black;">她们</span>在这个时代的键盘上留下的余温。</p>




页: [1]
查看完整版本: MicroApp 1.0 正式发布