micro-frontends
SPA(单页面应用)的最主要特征是:
整个应用通过一个 HTML 页面加载,页面切换由前端路由实现,动态更新视图而无需重新加载页面。
微前端 的核心思想是让 组件 或 应用 可以跨应用引用和集成。多个独立的前端应用(通常由不同团队开发、部署和维护)可以在同一个页面中协同工作
CORS
// good
const img = Object.assign(document.createElement('img'), { src: 'http://127.0.0.1:5051/1.jpg', alt: 'Description' })
container.appendChild(img);
// blocked by CORS policy
const response = await fetch('http://127.0.0.1:5051/1.jpg');
在微前端架构中,
模块联邦(Module Federation) 是一种常用的技术,允许多个独立的子应用共享代码,并将它们集成到一个基座应用中。
// webpack.config.js
const { ModuleFederationPlugin } = require("webpack").container;
module.exports = {
plugins: [
new ModuleFederationPlugin({
name: "remote",
filename: "remoteEntry.js",
exposes: {
"./HelloWorld": "./src/HelloWorld",
},
}),
],
};
