@farris/cli 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/add-project.js +2 -1
- package/lib/commands/add-project.js.map +1 -1
- package/lib/commands/build.js +2 -2
- package/lib/commands/build.js.map +1 -1
- package/lib/commands/create-app-options.js +5 -3
- package/lib/commands/create-app-options.js.map +1 -1
- package/lib/commands/create-app.js +4 -4
- package/lib/commands/create-app.js.map +1 -1
- package/lib/commands/create.js +221 -160
- package/lib/commands/create.js.map +1 -1
- package/lib/common/constant.js +2 -0
- package/lib/common/constant.js.map +1 -1
- package/lib/common/get-vite-config.js +28 -4
- package/lib/common/get-vite-config.js.map +1 -1
- package/lib/common/workspace-contract.js +2 -0
- package/lib/common/workspace-contract.js.map +1 -1
- package/lib/index.js +6 -4
- package/lib/index.js.map +1 -1
- package/package.json +87 -87
- package/templates/create/.gitignore.tpl +1 -0
- package/templates/create/package.json +1 -0
- package/templates/mobile/.gitignore.tpl +1 -0
- package/templates/mobile/farris.config.mjs +4 -0
- package/templates/mobile/package.json +1 -0
- package/templates/mobile/src/main.ts +39 -5
- package/templates/mobile/src/micro-app.d.ts +20 -0
- package/templates/mobile/src/router/index.ts +3 -2
- package/templates/web/.gitignore.tpl +1 -0
- package/templates/web/farris.config.mjs +4 -0
- package/templates/web/package.json +1 -0
- package/templates/web/src/App.vue +4 -0
- package/templates/web/src/main.ts +39 -5
- package/templates/web/src/micro/context.ts +26 -0
- package/templates/web/src/micro-app.d.ts +20 -0
- package/templates/web/src/router/index.ts +3 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { LocaleService } from '@farris/ui-vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 订阅主应用通过 microApp.setGlobalData 下发的运行上下文(语言 / 主题)。
|
|
5
|
+
* 仅在微前端(micro-app)环境中生效,独立运行时不做任何处理。
|
|
6
|
+
*/
|
|
7
|
+
export function setupMicroAppContext(): void {
|
|
8
|
+
if (!window.__MICRO_APP_ENVIRONMENT__) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
window.microApp?.addGlobalDataListener?.((data) => {
|
|
13
|
+
if (!data) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// 语言:主应用下发 language,同步 Farris 组件库语言
|
|
17
|
+
const i18n = (LocaleService as any)?.i18n;
|
|
18
|
+
if (typeof data.language === 'string' && i18n?.global?.locale) {
|
|
19
|
+
i18n.global.locale.value = data.language;
|
|
20
|
+
}
|
|
21
|
+
// 主题:主应用下发 theme,写入根元素供主题样式使用
|
|
22
|
+
if (typeof data.theme === 'string') {
|
|
23
|
+
document.documentElement.setAttribute('data-theme', data.theme);
|
|
24
|
+
}
|
|
25
|
+
}, true);
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
/** micro-app 子应用环境标记(由宿主注入) */
|
|
6
|
+
__MICRO_APP_ENVIRONMENT__?: boolean;
|
|
7
|
+
/** 宿主注入的 micro-app API */
|
|
8
|
+
microApp?: {
|
|
9
|
+
addGlobalDataListener?: (callback: (data: any) => void, immediately?: boolean) => void;
|
|
10
|
+
setGlobalData?: (data: Record<string, any>) => void;
|
|
11
|
+
getData?: () => Record<string, any> | null;
|
|
12
|
+
router?: {
|
|
13
|
+
getBaseAppRouter?: () => any;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** 微前端生命周期:宿主会调用这两个方法 */
|
|
17
|
+
mount?: () => void;
|
|
18
|
+
unmount?: () => void;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRouter,
|
|
1
|
+
import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router';
|
|
2
2
|
|
|
3
3
|
// 生成器(farris-cli generate view --with-route)依赖下面的 routes 数组赋值形式;
|
|
4
4
|
// 改动结构会导致路由无法自动注册。
|
|
@@ -16,7 +16,8 @@ export const routes: RouteRecordRaw[] = [
|
|
|
16
16
|
];
|
|
17
17
|
|
|
18
18
|
const router = createRouter({
|
|
19
|
-
|
|
19
|
+
// hash 路由:微前端(IBP)下子应用 location 由宿主接管,hash 模式最稳妥
|
|
20
|
+
history: createWebHashHistory(),
|
|
20
21
|
routes
|
|
21
22
|
});
|
|
22
23
|
|