GithubHelp home page GithubHelp logo

bo1839 / m-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ambit-tsai/m-app

0.0 0.0 0.0 961 KB

📦 微应用容器组件,整合 Web Components 与同源 iframe,利用原生特性实现应用间的完美隔离,使用如 iframe 般简便,却超脱 iframe 的局限。像 iframe 般容易上手的微前端解决方案,你值得一试!

License: Apache License 2.0

JavaScript 26.09% TypeScript 42.19% CSS 0.50% HTML 3.14% Vue 28.08%

m-app's Introduction

<m-app>

可能是你见过最简单的微前端解决方案,一行代码即可实现应用的接入 😎

<m-app entry="http://example.com/path/to/entry.html"></m-app>

体验一下,并且可以在线接入你的应用 🎉

  1. Gitee Pages
  2. GitHub Pages

📃 简介

m-app 将应用的 DOM 树置于 Shadow DOM 中维护,从而实现 DOM 树独立以及 CSS 隔离。而 JavaScript 代码则置于同源 iframe 中运行,由 iframe 提供独立的运行环境,并劫持 iframe 中 documentdocument.headdocument.body 等元素对象的方法,重定向到 Shadow DOM 中对应的元素上去。此外,还劫持了普通元素上有引入新元素能力的方法,如 appendChildreplaceChild 等,分析其中的 <script> 元素,并置于 iframe 中运行。

m-app 的 Shadow DOM 结构如下:

           ├─<iframe hidden>  
           │                 ├─<meta>
ShadowRoot─│        ├─<head>─├─<title>
           │        │        ├─...
           ├─<html>─│
                    │        ├─<h1>
                    ├─<body>─├─<div>
                             ├─...

m-app 的 Shadow DOM 与正常的 DOM 结构基本一致,降低应用接入的改造成本。

                             ├─<meta>
                    ├─<head>─├─<title>
                    │        ├─...
   Document──<html>─│
                    │        ├─<h1>
                    ├─<body>─├─<div>
                             ├─...

✨ 特性

  1. 运行时集成,应用可独立开发、部署、升级
  2. HTML Entry
  3. 天然支持 DOM、CSS、JS 隔离
  4. 不限制接入应用的技术栈
  5. 支持多应用并行
  6. 支持 <script> 的 type="module"、defer、async 等原生特性

⬇️ 安装

npm i -S @ambit_tsai/m-app

🔨 使用

import '@ambit_tsai/m-app';

或者

<script src="path/to/m-app.js"></script>

更多信息请查看 Wiki

☎️ 联系

  1. 微信: ambit_tsai
  2. QQ群: 663286147
  3. 邮箱: [email protected]

m-app's People

Contributors

ambit-tsai avatar

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.