Coder Social home page Coder Social logo

yuzhanglong / mf-lite Goto Github PK

View Code? Open in Web Editor NEW
159.0 3.0 20.0 6.07 MB

:tada: 优雅且实用的基于 webpack module federation 的微前端解决方案 / Elegant and practical micro front-end solution based on webpack module federation.

Home Page: https://yuzhanglong.feishu.cn/wiki/wikcncmRDZCUJRigluH7skQbtvg

License: MIT License

JavaScript 14.68% TypeScript 85.32%
webpack module-federation microfrontend webpack5 intl microfrontend-architecture react

mf-lite's Introduction


基于 Webpack 5 Module Federation,优雅且实用的微前端解决方案。

介绍

mf-lite 是一个基于 Webpack 5 Module Federation 来实现模块共享、qiankun 来做隔离沙箱的微前端解决方案,它提供以下内容:

  • 一个通过命令行快速创建基座应用或者微前端应用的脚手架, 提供项目初始化依赖及开发、构建脚本。npm Version

  • 一个核心工具库, 它可以:npm Version

    • 基于 Webpack Module Federation 特性,让微前端架构下的的库共享(share library)、甚至模块共享(share module) 成为可能,且使用更加优雅、易于维护。
    • 自动生成、处理开发、生产可用的 webpack 的复杂配置项,用户基本上无需直接接触 webpack 的相关配置。
    • 支持生成远程模块的 typescript 类型定义。
  • 一个基于 node.js、方便独立开发微应用的 HTTP 请求代理工具, 使微应用的独立开发方式更加优雅。npm Version

对于用户来说,唯一需要做的就是拉取模板、然后加上一些十分简单的配置,剩下的和平常的开发流程别无二致。

特性

📦 开箱即用:你只需要执行几行命令即可拉取相应的模板代码并把项目跑起来,包括基座应用和微前端应用,无需处理构建工具的复杂配置。

🤩 typescript 支持:模块的生产者和消费者均可自动生成/消费相关的 typescript 类型定义。

🚀 舒适的开发体验:开发体验与常规应用一致、完美接入 qiankun 微前端沙箱库、基座和微应用开发都支持热更新,类型定义的生成也不会打断正常的开发流程。

🔨 独立开发与部署:基于提供的代理工具,微应用开发者在单独开发微应用时,无需启动基座或者其它微应用。

🌟 轻量的项目模板:脚手架生成的初始项目只保留微前端相关的核心依赖,其它第三方库的选型(如 ui 组件库、状态管理库)交由开发者全权管理。

快速开始

安装脚手架工具

npm install @mf-lite/cli -g

在交互式命令行中创建项目

mf-lite create

安装依赖、执行项目

npm install
npm run dev:serve

更多信息以及实践方案,请查看文档

案例

快速开始: 最简单的项目 DEMO,开箱即用,全部在本地运行开发。子应用能够共享基座应用暴露出来的模块或者 npm 包。

微应用独立开发: 单独微应用的开发模式,基于部署在远程的基座开发,微应用基于它运行、消费其依赖。

远程部署案例: 通过配置来实现远程部署,其实现效果就是上文的 在线 DEMO

多个子应用部署案例: 一个在同一个页面运行多个微应用的案例。

TIP: 所有案例都可以在本仓库的 examples 目录下找到。

它是如何工作的

请参考这篇文章

License

MIT @yuzhanglong

mf-lite's People

Contributors

dependabot[bot] avatar yuzhanglong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mf-lite's Issues

新建模版报错,这个和node的版本有关吗?

/usr/local/lib/node_modules/@mf-lite/cli/node_modules/npm-check-updates/lib/index.js:428
throw err
^

Error: Command failed with ENOENT: plop --plopfile /usr/local/lib/node_modules/@mf-lite/cli/node_modules/@attachments/assets/lib/configurations/node-plop/micro-fe-generator.js
spawn plop ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:477:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn plop',
path: 'plop',
spawnargs: [
'--plopfile',
'/usr/local/lib/node_modules/@mf-lite/cli/node_modules/@attachments/assets/lib/configurations/node-plop/micro-fe-generator.js'
],
originalMessage: 'spawn plop ENOENT',
shortMessage: 'Command failed with ENOENT: plop --plopfile /usr/local/lib/node_modules/@mf-lite/cli/node_modules/@attachments/assets/lib/configurations/node-plop/micro-fe-generator.js\n' +
'spawn plop ENOENT',

通过exposes共享第三方依赖的问题

假设将lodash通过exposes实现共享,那能够满足其他app中import {get} from 'lodash'的使用,但是import get from 'lodash/get'这种带路径就不行了,而且不能保证所有第三方依赖包都在入口有暴露

求解惑:远程组件this的指向

我们的技术栈时vue,我们的远程模块A项目使用了一些挂载在vue.prototype上的方法,还有全局的自定义指令,router等等,现在要在另一个项目B上使用,this实例就变成了B。这种情况如何解决?

【Bug】ScriptExternalLoadError

在完全按文档的步骤跑
1、npm i @mf-lite -g
2、分别生成两个模板项目,进行npm i & npm run dev:serve

刚开始项目打开成功,访问正常,隔一段时间后显示如下错误,期间没有任何修改代码的操作

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.