当前位置: 首页 > wzjs >正文

企业网站建设报价上海最专业的seo公司

企业网站建设报价,上海最专业的seo公司,wordpress完整教程,怎么做刷钻网站以下是一个完整的 Angular 微前端示例,其中使用的是 Module Federation 和 npx-build-plus 实现了主应用(Shell)与子应用(Remote)的集成。 🛠️ 项目结构 angular-mf/ ├── shell-app/ # 主应用&…

        以下是一个完整的 Angular 微前端示例,其中使用的是 Module Federation 和 npx-build-plus 实现了主应用(Shell)与子应用(Remote)的集成。

🛠️ 项目结构

angular-mf/
├── shell-app/       # 主应用(Shell)
├── remote-app/      # 子应用(Remote)
├── angular.json     # Angular CLI 配置
└── package.json     # 项目依赖

1️⃣ 安装依赖

首先,确保你已安装 npx-build-plus:

ng add ngx-build-plus

然后,安装 @angular-architects/module-federation:

npm install @angular-architects/module-federation --save-dev

2️⃣ 配置 Remote 应用(子应用)

在remote-app/webpack.config.js 中,配置ModuleFederationPlugin:

const { ModuleFederationPlugin } = require('webpack').container;module.exports = {output: {uniqueName: 'remoteApp',publicPath: 'auto',},plugins: [new ModuleFederationPlugin({name: 'remoteApp',filename: 'remoteEntry.js',exposes: {'./RemoteModule': './src/app/remote/remote.module.ts',},shared: {'@angular/core': { singleton: true, strictVersion: true },'@angular/common': { singleton: true, strictVersion: true },'@angular/router': { singleton: true, strictVersion: true },},}),],
};

3️⃣ 配置 Shell 应用(主应用)

在 shell-app/webpack.config.js 中,配置ModuleFederationPlugin:

const { ModuleFederationPlugin } = require('webpack').container;module.exports = {output: {uniqueName: 'shellApp',},plugins: [new ModuleFederationPlugin({name: 'shellApp',remotes: {remoteApp: 'remoteApp@http://localhost:4201/remoteEntry.js',},shared: {'@angular/core': { singleton: true, strictVersion: true },'@angular/common': { singleton: true, strictVersion: true },'@angular/router': { singleton: true, strictVersion: true },},}),],
};

4️⃣ 配置 Angular.json File + Angular 路由

        angular.json文件配置如下:angular.json 配置的关键部分是如何集成 npx-build-plus 以支持 Webpack Module Federation。

angular.json 配置说明

🧭 关键修改目标

  1. 使用 npx-build-plus 替代默认@angular-devkit/build-angular:browser

  2. 添加extraWebpackConfig 指向自定义的 Webpack 配置文件

  3. 配置输出格式(如 umdModules(非必须)、outputPath)

📁 angular.json 配置片段

{"projects": {"shell-app": {"architect": {"build": {"builder": "ngx-build-plus:browser","options": {"outputPath": "dist/shell-app","index": "src/index.html","main": "src/main.ts","polyfills": "src/polyfills.ts","tsConfig": "tsconfig.app.json","aot": true,"assets": ["src/favicon.ico", "src/assets"],"styles": ["src/styles.scss"],"scripts": [],"extraWebpackConfig": "webpack.config.js","umdModuleIds": {"@angular/core": "ng.core","@angular/common": "ng.common","@angular/router": "ng.router"}},"configurations": {"production": {"optimization": true,"outputHashing": "all","sourceMap": false,"extractCss": true,"namedChunks": false,"fileReplacements": [{"replace": "src/environments/environment.ts","with": "src/environments/environment.prod.ts"}]}}},"serve": {"builder": "ngx-build-plus:dev-server","options": {"browserTarget": "shell-app:build"},"configurations": {"production": {"browserTarget": "shell-app:build:production"}}}}}}
}

📦 额外建议

  • 确保webpack.config.js 文件存在于根目录或指定位置。

  • 如果你有多个环境配置(如 staging/test),也可以扩展configurations 。

  • 如果你使用webpack.prod.config.js,可以在生产配置中加上extraWebpackConfig 覆盖。

在shell-app/src/app/app-routes.ts 中,配置动态加载 Remote 模块:

import { Routes } from '@angular/router';
import { loadRemoteModule } from '@angular-architects/module-federation';export const routes: Routes = [{path: 'remote',loadChildren: () =>loadRemoteModule({remoteName: 'remoteApp',exposedModule: './RemoteModule',}).then((m) => m.RemoteModule),},
];

5️⃣ 启动应用

分别启动 Remote 和 Shell 应用:

# 启动 Remote 应用
cd remote-app
ng serve --port 4201# 启动 Shell 应用
cd shell-app
ng serve --port 4200

访问 http://localhost:4200/remote 即可加载 Remote 模块。


✅ 总结

  • 使用 Webpack 5 的 ModuleFederationPlugin 实现了主应用与子应用的动态模块共享。

  • 通过npx-build-plus扩展了 Angular CLI 的构建功能,支持自定义 Webpack 配置。

  • 采用@angular-architects/module-federation提供的 loadRemoteModule实现了 Angular 路由的懒加载远程模块。

http://www.dtcms.com/wzjs/128787.html

相关文章:

  • 企业做淘宝网站需要多少钱郑州seo方案
  • 建设产品网站课程设计石家庄百度搜索引擎优化
  • 贸易公司网站模板网站推广软件费用是多少
  • 网站建设神州互动网络推广怎么做好
  • 哪个网站做清洁的活多做外贸网站的公司
  • 电商网站建设比较好的校园推广
  • 建设一个网站需要什么百度推广费用怎么算
  • 做网站设计要适配到手机端么百度热搜榜怎么打开
  • wordpress怎么做淘客网站万能bt搜索引擎
  • 建设高效的政府门户网站徐州百度快照优化
  • asp商业网站源码seo的作用主要有
  • 搬瓦工做网站seo公司上海
  • 济南定制网站制作公司热点新闻事件今日最新
  • 爱是做的电影网站吗学网络营销好就业吗
  • 国外优秀网站百度推广账户优化方案
  • 大型网站建设基本流程全网模板建站系统
  • 福州网站建设专业定制广州市人民政府新闻办公室
  • 个人网站备案怎么办理湖南关键词优化推荐
  • 网站开发的技术可行性怎么写武汉seo优化顾问
  • ofo的网站用什么做的seo网站推广专员
  • 上线了 网站网页设计首页制作
  • 怎么做网络推广网站百度手机助手下载2022新版
  • 政府网站架构工具百度seo新算法
  • ps如何做网站导航图免费申请网站
  • 设置网站关键词怎么做网站运营公司
  • 菏泽北京网站建设html网页制作用什么软件
  • wordpress申请网站seo指的是搜索引擎营销
  • 北京做网站要多少钱网站怎么优化推荐
  • 变身变装 wordpress安徽seo网络优化师
  • 怎样才能申请网站2021年近期舆情热点话题