Giter Club home page Giter Club logo

wujie's Introduction

logo

wujie(无界)

无界微前端是一款基于 Web Components + iframe 微前端框架,具备成本低、速度快、原生隔离、功能强等一系列优点。

文档

动机:动机

文档详见:文档

演示详见:demo

背景

微前端已经是一个非常成熟的领域了,但开发者不管采用哪个现有方案,在适配成本、样式隔离、运行性能、页面白屏、子应用通信、子应用保活、多应用激活、vite 框架支持、应用共享等用户核心诉求都或存在问题、或无法提供支持。

Web Components 是一个浏览器原生支持的组件封装技术,可以有效隔离元素之间的样式,iframe 可以给子应用提供一个原生隔离的运行环境,相比自行构造的沙箱 iframe 提供了独立的 window、document、history、location,可以更好的和外部解耦。无界微前端采用 webcomponent + iframe 的沙箱模式,在实现原生隔离的前提下比较完善的解决了上述问题。

特性

  1. 成本低
    • 主应用使用成本低
    • 子应用适配成本低
  2. 速度快
    • 子应用首屏打开速度快
    • 子应用运行速度快
  3. 原生隔离
    • css 样式通过 Web Components 可以做到严格的原生隔离
    • js 运行在 iframe 中做到严格的原生隔离
  4. 功能强大
    • 支持子应用保活
    • 支持子应用嵌套
    • 支持多应用激活
    • 支持应用共享
    • 支持去中心化通信
    • 支持生命周期钩子
    • 支持插件系统
    • 支持 vite 框架

快速上手

直接使用

  • 安装
npm install wujie -S
  • 使用
import { startApp } from "wujie";

startApp({ name: "唯一id", url: "子应用路径", el: "容器", sync: true });

vue 框架

  • 安装
# vue2 框架
npm i wujie-vue2 -S
# vue3 框架
npm i wujie-vue3 -S
  • 引入
// vue2
import WujieVue from "wujie-vue2";
Vue.use(WujieVue);
// vue3
import WujieVue from "wujie-vue3";
app.use(WujieVue);
  • 使用
<WujieVue
  width="100%"
  height="100%"
  name="xxx"
  :url="xxx"
  :sync="true"
  :fetch="fetch"
  :props="props"
  :beforeLoad="beforeLoad"
  :beforeMount="beforeMount"
  :afterMount="afterMount"
  :beforeUnmount="beforeUnmount"
  :afterUnmount="afterUnmount"
></WujieVue>

react 框架

  • 安装
npm i wujie-react -S
  • 引入
import WujieReact from "wujie-react";
  • 使用
<WujieReact
  width="100%"
  height="100%"
  name="xxx"
  url="{xxx}"
  sync="{true}"
  fetch="{fetch}"
  props="{props}"
  beforeLoad="{beforeLoad}"
  beforeMount="{beforeMount}"
  afterMount="{afterMount}"
  beforeUnmount="{beforeUnmount}"
  afterUnmount="{afterUnmount}"
></WujieReact>

常见问题

详见文档

本地开发

运行以下脚本,可以本地开发无界微前端框架,支持实时编译调试开发。

pnpm i                  // 安装包依赖,务必使用pnpm
npm run start           // 启动所有应用

One more thing

无界微前端解决方案来源于团队的无极低代码平台,通过无界微前端,存量页面和低代码页面可以丝滑的互相内嵌,欢迎体验【腾讯无极低代码】

wujie's People

Contributors

4brother avatar aladdin-add avatar alfred-skyblue avatar azronchan avatar dengbox avatar erkelost avatar evolzzz avatar hailworld avatar heziqiang avatar iamxiyang avatar jardenliu avatar lexmin0412 avatar ljquan avatar micheal-zhibin avatar molunerfinn avatar pgfish avatar sauron0914 avatar sondh0127 avatar squallliu avatar sunyfg avatar sunyuis avatar woshirubbish avatar wxwzl avatar xchen1995 avatar xland avatar xusenbiao avatar xuzhidanxu avatar yiludege avatar ysherlock avatar zhuzhuman978 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  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

wujie's Issues

主应用菜单点击路由变化问题

主应用通过点击菜单跳转子应用页面,路由同步开启。
当我再次点击主应用同样的菜单时,会改变路由,后面的参数丢了。

主应用、子应用均为vite+vue3。使用element plus, 菜单组件,开起路由模式

element-ui dialog弹框里面写的下拉框el-select左右错位

描述bug
element-ui dialog弹框里面写的下拉框el-select左右错位
左侧菜单栏是主应用,右侧是子应用;右侧里面的dialog弹框里面写的el-select下拉框错位 加了body{position:relative;}上下错位好了 但还是有左右错位问题

如何复现
给出详细的复现步骤
1、第一步 xxx
2、 第二步 xxx

错误截图
1660721411763

最小复现仓库或者地址
重要!!!,请尽量给出复现仓库,这样能极大加快bug解决速度

js-excludes 和 css-excludes 建议支持函数或者正则

背景

比如我们现在接的子应用内部有百度 sdk 需要忽略,由主应用统一处理,但是子应用内部的百度 sdk 1、2、3版本都有,而且有 query 等各种情况,那么我们想忽略,就必须把所有子应用链接的版本都收集到,比较麻烦。

期望

能 js-excludes 和 css-excludes 支持正则表达式和字符串两张形式

子应用使用webpack module federation报错

子应用使用module federation引用其它module federation类型模块报错,有支持的方式吗?[
Uncaught (in promise) ScriptExternalLoadError: Loading script failed. (missing: http://localhost:4000/remoteEntry.js) while loading "./react" from webpack/container/reference/lib-app while loading "./react-dom" from webpack/container/reference/lib-app

单 Vue 应用不会渲染

目前子应用只是一个简单的单Vue应用,没有用vue-router、vuex、webpack等,但是组件没有渲染,iframe中可以正常显示
控制台没有任何报错
image
image
image

是index.html的内联js没有执行吗?

第一个issues

话说,生产环境效果怎么样,有没什么坑啊

无界目前是否可以应用在生产级别的环境中

当前在做微前端框架选择,项目本身是vue2做主,ng1 ng2 vue2都有子,之前调研过qiankun,对于ng和ng1有一些不太友好的地方,恰巧这时候看到了无界,但是目前看下来好像没有什么具体产品验证,特此询问一下(没有别的意思,就是单纯问一下测试及验证的情况)

Windows系统无法正常运行start脚本

问题描述: 从GitHub仓库clone下来的代码,按照README文件本地开发中的步骤运行npm run start脚本,在Windows系统中无法正常启动example代码

环境信息:

  • os 版本:Windows10
  • npm 版本:8.11.0

报错截图:
image

vite的 主子应用 保活问题

子应用 alive设置为true
切换页面时还是会进入到wujie的window.__WUJIE_MOUNT __WUJIE_UNMOUNT中,
如果不生命周期改造 还是会重新加载
就是保活并没有生效

访问子应用跨域错误

我的子应用接口通过配置nginx已经支持跨域访问,但是通过主应用访问还是提示跨域错误。单独访问子应用正常

子应用通过css加载的图片无法显示

// Vue 2 / App.vue
<template>
    <div>
      [Test] img src
      <img src="./assets/logo.png" alt="">
    </div>
    <div>
      [Test] i background url
      <i class="icon-logo"></i>
    </div>
</template>
<style>
.icon-logo {
  display: inline-block;
  width: 100px;
  height: 100px;
  background: url("./assets/logo.png") 0 0 / 100px 100px no-repeat;
}
</style>

image

子应用独立运行可以正确显示 i 标签的图片
但是在主应用里运行子应用的时候就失效了

包管理工具升级为pnpm

现在安装包重复依赖太多太慢,采用hoist模式又出现各种诡异现状,准备升级到pnpm + lerna

IE11下 "EventTarget" 未定义

描述bug
IE11浏览器,在 creat-react-app 生成的 demo 项目下,引入 wujie-react,尝试渲染子应用,控制台显示 "EventTarget" 未定义

如何复现

1、第一步,通过 cra 生成最简demo项目
2、第二步,安装 creat-app-polyfill,在入口文件 index.js 中引入 “import "react-app-polyfill/ie11";”
image
3、第三步
改写 App 组件,注释无用css和图片等,保留 外层 div 结构,内部引入 wujie-react 组件
wujie-react 组件配置相关的 name 和 url(这里把 name和url 设置为同一个),width/height 100%
image

4、第四步,yarn build 打包项目,部署在本机 nginx,通过 IE11 浏览器进行访问
image

错误截图
image

错误代码定位在 common.ts 中的 EventTarget.prototype.addEventListen

最小复现仓库或者地址
重要!!!,请尽量给出复现仓库,这样能极大加快bug解决速度

vite的 主子应用 保活问题

子应用 alive设置为true
切换页面时还是会进入到wujie的window.__WUJIE_MOUNT __WUJIE_UNMOUNT中,
如果不生命周期改造 还是会重新加载
就是保活并没有生效

请问有什么办法能在子应用中获取到主应用中的某个DOM节点

我这边有个特别的场景,需要在子应用中获取到主应用中某个DOM节点

以前项目未采用微前端方案时,是直接通过document.querySelector(xxx),但是现在接入wujie后,我发现document.querySelector会从shadowRoot中找,这样以前代码就有bug

请问有什么好办法解决吗?
感谢

如果不开启路由同步,会出现什么问题?

我搭建了一个demo,开启路由同步后,路由后面始终会携带参数。当关闭路由同步后,demo中的效果暂时没发现有什么问题。所以想请教一下,如果关闭后会有什么问题?

主应用和子应用均为vite + vue3。

顶层声明的 var 变量,文件之间无法共享

描述bug
script 文件声明的 var 变量,没有挂到 window 对象上,script 之间无法共享

如何复现
创建一个简单的文件,使用wujie加载报错
`

<script> var ttt = 10 </script> <script> console.log('ttt', ttt) </script>
`

错误截图
如果有可以将截图带上

最小复现仓库或者地址
重要!!!,请尽量给出复现仓库,这样能极大加快bug解决速度

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.