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

元谋网站建设百度搜索引擎的特点

元谋网站建设,百度搜索引擎的特点,广卅网络设计公司,手机网站开发入门1. 项目结构 microfrontend-demo/ ├── shell/ # 主应用 (Shell) ├── mfe1/ # 微前端应用1 ├── mfe2/ # 微前端应用2 └── shared/ # 共享库 2. 主应用 (Shell) 配置 shell/webpack.config.js con…

1. 项目结构

microfrontend-demo/
├── shell/                # 主应用 (Shell)
├── mfe1/                 # 微前端应用1
├── mfe2/                 # 微前端应用2
└── shared/               # 共享库

2. 主应用 (Shell) 配置

shell/webpack.config.js
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");module.exports = {output: {uniqueName: "shell",publicPath: "auto"},optimization: {runtimeChunk: false},plugins: [new ModuleFederationPlugin({remotes: {"mfe1": "mfe1@http://localhost:4201/remoteEntry.js","mfe2": "mfe2@http://localhost:4202/remoteEntry.js"},shared: {"@angular/core": { singleton: true, strictVersion: true },"@angular/common": { singleton: true, strictVersion: true },"@angular/router": { singleton: true, strictVersion: true },"@angular/common/http": { singleton: true, strictVersion: true },// 其他共享库...}})]
};
shell/src/app/app-routing.module.ts

使用:RouterModule.forRoot(routes)

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';const routes: Routes = [{path: '',pathMatch: 'full',redirectTo: 'home'},{path: 'home',loadChildren: () => import('./home/home.module').then(m => m.HomeModule)},{path: 'mfe1',loadChildren: () => import('mfe1/Module').then(m => m.Mfe1Module)},{path: 'mfe2',loadChildren: () => import('mfe2/Module').then(m => m.Mfe2Module)},{path: '**',redirectTo: 'home'}
];@NgModule({imports: [RouterModule.forRoot(routes)],exports: [RouterModule]
})
export class AppRoutingModule { }
shell/src/app/app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { RouterModule } from '@angular/router';@NgModule({declarations: [AppComponent],imports: [BrowserModule,RouterModule,AppRoutingModule],providers: [],bootstrap: [AppComponent]
})
export class AppModule { }

3. 微前端应用1 (MFE1) 配置

mfe1/webpack.config.js

只需导出包含所有路由配置的Module即可

const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");module.exports = {output: {uniqueName: "mfe1",publicPath: "auto"},optimization: {runtimeChunk: false},plugins: [new ModuleFederationPlugin({name: "mfe1",filename: "remoteEntry.js",exposes: {'./Module': './src/app/mfe1/mfe1.module.ts',},shared: {"@angular/core": { singleton: true, strictVersion: true },"@angular/common": { singleton: true, strictVersion: true },"@angular/router": { singleton: true, strictVersion: true },// 其他共享库...}})]
};
mfe1/src/app/mfe1/mfe1.module.ts

使用 RouterModule.forChild(routes) 时,若未将所有路由配置集中在一个模块中,则需在每个组件内单独添加 RouterModule.forChild([{path:'',component:''}]) 配置。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { Mfe1Component } from './mfe1.component';const routes: Routes = [{ path: '', component: Mfe1Component },{ path: 'details', loadChildren: () => import('./details/details.module').then(m => m.DetailsModule) }
];@NgModule({declarations: [Mfe1Component],imports: [CommonModule,RouterModule.forChild(routes)]
})
export class Mfe1Module { }

4. 微前端应用2 (MFE2) 配置

mfe2/webpack.config.js

只需导出包含所有路由配置的Module即可

const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");module.exports = {output: {uniqueName: "mfe2",publicPath: "auto"},optimization: {runtimeChunk: false},plugins: [new ModuleFederationPlugin({name: "mfe2",filename: "remoteEntry.js",exposes: {'./Module': './src/app/mfe2/mfe2.module.ts',},shared: {"@angular/core": { singleton: true, strictVersion: true },"@angular/common": { singleton: true, strictVersion: true },"@angular/router": { singleton: true, strictVersion: true },// 其他共享库...}})]
};

mfe2/src/app/mfe2/mfe2.module.ts

使用 RouterModule.forChild(routes) 时,若未将所有路由配置集中在一个模块中,则需在每个组件内单独添加 RouterModule.forChild([{path:'',component:''}]) 配置。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { Mfe2Component } from './mfe2.component';const routes: Routes = [{ path: '', component: Mfe2Component },{ path: 'settings', loadChildren: () => import('./settings/settings.module').then(m => m.SettingsModule) }
];@NgModule({declarations: [Mfe2Component],imports: [CommonModule,RouterModule.forChild(routes)]
})
export class Mfe2Module { }

5. 共享库配置

shared/package.json
{"name": "shared","version": "1.0.0","peerDependencies": {"@angular/core": "^15.0.0","@angular/common": "^15.0.0","@angular/router": "^15.0.0"}
}

6. 导航组件示例

shell/src/app/nav/nav.component.ts
import { Component } from '@angular/core';
import { Router } from '@angular/router';@Component({selector: 'app-nav',template: `<nav><button (click)="navigateTo('home')">Home</button><button (click)="navigateTo('mfe1')">MFE1</button><button (click)="navigateTo('mfe2')">MFE2</button></nav>`
})
export class NavComponent {constructor(private router: Router) {}navigateTo(route: string): void {this.router.navigate([route]);}
}

7. 环境配置

shell/src/environments/environment.ts
export const environment = {production: false,mfe1Url: 'http://localhost:4201/remoteEntry.js',mfe2Url: 'http://localhost:4202/remoteEntry.js'
};

8. 启动脚本

在 package.json 中添加并行启动脚本:

"scripts": {"start": "npm-run-all --parallel start:shell start:mfe1 start:mfe2","start:shell": "ng serve shell -o --port 4200","start:mfe1": "ng serve mfe1 -o --port 4201","start:mfe2": "ng serve mfe2 -o --port 4202"
}

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

相关文章:

  • 技术网站建设电商seo搜索引擎优化
  • 网页视频下载器免费烟台seo外包
  • 太原做网站页面的百度店面定位怎么申请
  • 西安网站建设xazxcy站长之家alexa排名
  • 天津房地产集团网站建设seo网络推广技术员招聘
  • 做一个个人主页的网站怎么做青岛谷歌优化
  • 一般网站建设流程有哪些步骤建站推广网站
  • 电商网站的相同点申请自媒体平台注册
  • 肥东网站建设百度平台商家订单查询
  • 上饶市建设局有什么网站谷歌浏览器最新版本
  • 网站开发必学的技巧有哪些福州整站优化
  • 网站下方一般放什么搜索引擎营销流程是什么?
  • 电子网站建发广告推广平台
  • 百度企业网站建设免费网站建设seo
  • 山西大同专业网站建设价格小程序开发费用一览表
  • 做护士题的那个网站是什么网络整合营销4i原则是指
  • 做门户网站 cms中国十大互联网公司排名
  • 网站后台账户密码查关键词排名软件
  • wordpress怎麽换主题旺道网站优化
  • 茂名优化网站建设东莞网络营销推广专业
  • 狮山建网站app推广方案
  • 点金wordpress网站seo分析案例
  • 深圳网站建设潮动九州写软文赚钱的平台都有哪些
  • 济宁做网站哪家比较好seo入门到精通
  • 长春小程序开发制作seo自然优化排名技巧
  • 乐陵疫情最新消息今天宁波网站推广网站优化
  • 网页游戏排行榜前十微信小程序app优化
  • 网站怎么做百度能搜到中视频自媒体平台注册官网
  • 外包公司设计完网站谁负责运营长沙seo推广
  • 企业手机网站建设策划书多少关键词排名优化软件