打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Rules of Micro-Frontends

 参考资料:https://medium.com/swlh/rules-of-micro-frontends-7b96c10dde9

This is an opinionated list of best practices when designing applications that follow the Micro-frontend pattern. Each “rule” should be examined and its benefits/downsides evaluated against your specific use case.

Zero coupling between Micro-frontends

To achieve the benefits of this architecture, accidental coupling should be avoided as much as possible; this will unlock the flexibility and scalability that the Micro-Frontend pattern has to offer as well as future-proofing your applications by allowing incremental upgrades or future complete rewrites of parts of your application.

Each Micro-frontend should be able to render in isolation or inside a container application. The data required should be loaded by each Micro-Frontend and avoid data waterfalls.

Do:

  • ✅ Share libraries that can be swapped without affecting other Micro-frontends.

  • ✅ Load all the data it needs to render.

Do Not:

  • ❌ Have a centralised store/share data across different Micro-Frontends.

  • ❌ Share libraries that are in active development.

Separate Code Bases

Each Micro-Frontend should have its own codebase and the version control of choice shouldn’t have any impact on the way the project is developed or deployed. Having all projects under a single monorepo or individual repositories is fine.

Do:

  • ✅ Use Monorepos.

  • ✅ Use individual repos.

Each Micro-frontend should be deployed independently

Each Micro-Frontend should have it’s own CI/CD pipeline and be able to deploy to production on demand without any dependencies on other Micro-frontends. A common antipattern that should be avoided is “The deployment queue of hell” where different Micro-frontends are so tightly coupled that they need to be deployed in a specific order to avoid breaking the application.

Do:

  • ✅ Have separate CI/CD pipelines.

  • ✅ Release on demand.

Do Not:

  • ❌ Have Release schedules.

  • ❌ Have incremental/sequential deployments that require previous versions.

Micro-Frontends should be tested Independently

Because Micro-Frontends are required to render independently as well as inside a container application, it makes sense to also test them independently using unit and integration tests for both scenarios.

Do:

  • ✅ Have unit and integration tests for each Micro-Frontend rendering in isolation.

  • ✅ Run integration tests for Micro-Frontends rendering inside the container applications as part of end-to-end testing.

Micro-Frontends should be versioned

When a new Micro-Fronted is deployed to production, the previous version should not be deleted and the new version should be tagged with a version number using semantic versioning or similar. It is up to the container applications to decide what specific version of a particular Micro-Frontend to use (Managed) or always use the latest version instead (Evergreen).

Do:

  • ✅ Use Semantic versioning.

  • ✅ Use a specific version or “latest”.

Do Not:

  • ❌ Require a global deployment to change versions.

  • ❌ Delete previous versions.

Minimal Communication

Communication between Micro-Frontends should be minimal and simple, avoiding global state and framework-specific solutions as much as possible.

If two or more Micro-Frontends are sharing a lot of messages to provide their minimal functionality, they might be too tightly coupled and they could share a similar enough purpose that they should be considered to be integrated into one.

Do:

  • ✅ Keep messages small and simple.

  • ✅ Avoid state and communication frameworks if possible.

Do Not:

  • ❌ Share state.

  • ❌ Have unnecessary communication.

CSS should be scoped

CSS from loaded from one Micro-fronted should not affect others.

Do:

  • ✅ Scope your CSS.

  • ✅ Use a CSS-in-JS or namespacing library (like CSS Modules).

Do Not:

  • ❌ Use global CSS.

Final Recommendations

  • ✅ Try to create autonomous teams.

  • ✅ Try to arrange your Micro-Frontends around business functionality.

  • ✅ Reusability is a nice “side effect” not the target.

  • ❌ Don’t Force this architectural style just because it is “new”.

  • ❌ You don’t need multiple javascript frameworks.

  • ❌ You don’t need a “micro-frontend framework”.

  • ❌ Micro-Frontends don’t have to be “micro”.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WebBrowser与IE的关系,如何设置WebBrowser工作在IE9模式下?
微前端(Micro Frontend ) 落地实施的一些具体例子
How to deploy an Astro site
纯python实现的web: tornado性能测试
avoid 的用法
CSS 参考手册(2)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服