ams
@ams-micro/main
核心framework,用户校验,导航,整体UI框架,css变量控制。
@ams-micro/common
公共配置,全局对象存放模块
@ams-micro/service-*
负责各功能开发,不同功能模块应当分离为不同包。
voyom.env.js
module.exports = {
dev: { //开发环境
test_service:
"testService@http://localhost:8601/service-two/testService.js",
},
trial: { //测试环境
test_service:
"testService@http://localhost:8601/service-two/testService.js",
},
prod: { //生产环境
test_service:
"testService@http://localhost:8601/service-two/testService.js",
},
};
该文件配置了test_service服务,的入口JS地址。
生产|测试地址根据实际情况变更。
引用格式为[服务名]@[服务入口文件绝对地址]。
src/router-main.ts
export const routerMain=[
{
path: "module-two",
//将test_service注册入 module-two目录下
module: () => import("test_service/testService"),
},
]
引用格式为import([定义的服务别名]/[服务输出的模块名])。
这样在module-two/路由下的页面便由test_service托管。
关于@voyom/vue-router:
webpack.config.js
new ModuleFederationPlugin({
name:`${configVal.serviceName}`,
filename:`${configVal.serviceName}.js`,
remotes:{},
/**
* 输出当前module ==> /dist/testService.js
*/
exposes:{
[`./${configVal.serviceName}`] : join(configVal.entry)
},
/**
* 提取共享包
*/
shared: {
vue: {
requiredVersion: deps["vue"]
},
"@ztwx/utils": {
requiredVersion: deps["@ztwx/utils"]
},
vuex: { requiredVersion: depsNative["vuex"] },
"vue-router": {
requiredVersion: deps["vue-router"],
},
"@voyo/http": {
requiredVersion: depsNative["@voyo/http"],
},
"@ams-micro/common": {
requiredVersion: "0.0.1",
},
"vue-property-decorator": {
requiredVersion: deps["vue-property-decorator"],
},
},
})
已配置的共享模块,在服务包运行|打包时,均不会被引入。
程序执行时,会从main中获取共享模块代码。
configVal 的配置参数会从voyom.env.js里获取
voyom.env.js
module.exports={
dev:{
entry: "src/main.ts",
baseUrl:"http://localhost:8601/service-two/",
serviceName: "testService",
},
trial:{
entry: "src/main.ts",
baseUrl:"http://localhost:3000/service-two/",
serviceName: "testService",
},
prod:{
entry: "src/main.ts",
baseUrl:"http://localhost:8601/service-two/",
serviceName: "testService",
}
}
src/main.ts
import {VoyoRouterChild} from "@voyom/vue-router";
const child= new VoyoRouterChild({
name:"test-service",
routes:[
{
path:"one-page",component:()=>import("./pages/one-page/one-page.vue")
},
{
path:"two-page",component:()=>import("./pages/two-page/two-page.vue")
}
]
});
export default child;
服务原文件应当输出一个default VoyoRouterChild实例。
注册成功后,会自动addRoute,服务中定义的路由。
http://localhost:8600中访问子服务页面子服务的baseUrl,务必配置为完整url,无论开发,生产。
基本请求样例:
import {global} from "@ams-micro/common";
const http=global.http;
http.xhr({
method: "post",
path: "/queryById",
json: {
"id":1
}
})
.toPromise()
.then(result=>{})
关于 @voyo/http