@farris/cli 2.3.0 → 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 +223 -169
- package/lib/commands/create.js.map +1 -1
- package/lib/common/constant.js +20 -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 -53
- package/templates/create/.gitignore.tpl +1 -0
- package/templates/create/package.json +1 -0
- package/templates/create/pnpm-workspace.yaml +1 -8
- package/templates/lib/package.json +3 -0
- package/templates/mobile/.gitignore.tpl +1 -0
- package/templates/mobile/farris.config.mjs +4 -0
- package/templates/mobile/package.json +3 -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 +3 -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
|
@@ -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
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath, URL } from 'node:url';
|
|
2
2
|
|
|
3
3
|
export default {
|
|
4
|
+
// 相对路径 base:微前端(IBP)与静态托管(iGIX iframe)都适用
|
|
5
|
+
base: './',
|
|
6
|
+
routerMode: 'hash',
|
|
7
|
+
// iife: IBP 微前端单文件产物(默认);如需普通 ESM 站点产物,执行 pnpm build:es
|
|
4
8
|
format: "<%= format %>",
|
|
5
9
|
// 输出目录 App模式默认值 './dist' Lib模式 './lib'
|
|
6
10
|
// outDir: fileURLToPath(new URL('./dist', import.meta.url)),
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "farris-cli dev",
|
|
8
8
|
"build": "farris-cli build -ep",
|
|
9
|
+
"build:es": "farris-cli build --format es --outDir dist-es",
|
|
9
10
|
"preview": "farris-cli preview",
|
|
10
11
|
"test": "vitest run",
|
|
11
12
|
"test:watch": "vitest",
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
"@farris/cli": "<%= cliVersion %>",
|
|
24
25
|
"@rushstack/eslint-patch": "^1.8.0",
|
|
25
26
|
"@vitejs/plugin-vue": "^5.2.4",
|
|
27
|
+
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
|
26
28
|
"@vue/eslint-config-prettier": "^9.0.0",
|
|
27
29
|
"@vue/eslint-config-typescript": "^13.0.0",
|
|
28
30
|
"@vue/test-utils": "^2.4.6",
|
|
@@ -33,6 +35,7 @@
|
|
|
33
35
|
"prettier": "^3.2.5",
|
|
34
36
|
"typescript": "~5.4.0",
|
|
35
37
|
"vite": "^5.4.19",
|
|
38
|
+
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
36
39
|
"vitest": "^3.2.4",
|
|
37
40
|
"vue-tsc": "^2.2.0",
|
|
38
41
|
"sass": "^1.90.0"
|
|
@@ -1,13 +1,47 @@
|
|
|
1
|
-
import { createApp } from 'vue';
|
|
1
|
+
import { createApp, type App as VueApp } from 'vue';
|
|
2
2
|
import FarrisVue from '@farris/ui-vue';
|
|
3
3
|
import '@farris/ui-vue/index.css';
|
|
4
4
|
import App from './App.vue';
|
|
5
5
|
import router from './router';<%= styleImport %>
|
|
6
6
|
import { localResources } from './locales';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
let app: VueApp | null = null;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
/** 挂载应用(微前端宿主会调用 window.mount) */
|
|
11
|
+
function mount(): void {
|
|
12
|
+
if (app) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
app = createApp(App);
|
|
16
|
+
app.use(FarrisVue, { basePath: '', locale: 'zh-CN', localResources });
|
|
17
|
+
app.use(router);
|
|
18
|
+
app.mount('#app');
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
// 微前端环境:按平台下发的 initialPath 定位菜单配置的页面(fullPath)
|
|
21
|
+
// hash 路由必须保留这段兜底;history 路由下平台 defaultPage 已能直接命中,这里是幂等兜底
|
|
22
|
+
if (window.__MICRO_APP_ENVIRONMENT__) {
|
|
23
|
+
const rawPath = window.microApp?.getData?.()?.initialPath;
|
|
24
|
+
if (typeof rawPath === 'string' && rawPath !== '') {
|
|
25
|
+
// 平台下发的 initialPath 通常不带前导斜杠(如 'form'),这里统一归一化
|
|
26
|
+
const initialPath = rawPath.startsWith('/') ? rawPath : '/' + rawPath;
|
|
27
|
+
if (initialPath !== '/') {
|
|
28
|
+
router.isReady().then(() => router.replace(initialPath)).catch(() => undefined);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 卸载应用(微前端宿主会调用 window.unmount) */
|
|
35
|
+
function unmount(): void {
|
|
36
|
+
app?.unmount();
|
|
37
|
+
app = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 微前端(micro-app)生命周期契约:必须暴露到 window
|
|
41
|
+
window.mount = mount;
|
|
42
|
+
window.unmount = unmount;
|
|
43
|
+
|
|
44
|
+
// 独立运行(浏览器直接访问 / iframe 嵌入)时自动挂载
|
|
45
|
+
if (!window.__MICRO_APP_ENVIRONMENT__) {
|
|
46
|
+
mount();
|
|
47
|
+
}
|
|
@@ -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
|
|