@farris/cli 2.3.6 → 2.3.8
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-app.js +1 -1
- package/lib/commands/add-app.js.map +1 -1
- package/lib/commands/add-lib.js +1 -1
- package/lib/commands/add-lib.js.map +1 -1
- package/lib/commands/add-micro.js +12 -0
- package/lib/commands/add-micro.js.map +1 -0
- package/lib/commands/add-project.js +12 -10
- package/lib/commands/add-project.js.map +1 -1
- package/lib/commands/build-components.js +2 -2
- package/lib/commands/build-components.js.map +1 -1
- package/lib/commands/build-lib.js +1 -1
- package/lib/commands/build-lib.js.map +1 -1
- package/lib/commands/create-app-options.js +14 -3
- package/lib/commands/create-app-options.js.map +1 -1
- package/lib/commands/create-options.js +36 -10
- package/lib/commands/create-options.js.map +1 -1
- package/lib/commands/create.js +21 -11
- package/lib/commands/create.js.map +1 -1
- package/lib/commands/workspace/create.js +2 -2
- package/lib/commands/workspace/create.js.map +1 -1
- package/lib/common/constant.js +1 -1
- package/lib/common/constant.js.map +1 -1
- package/lib/common/generate-app.js +3 -6
- package/lib/common/generate-app.js.map +1 -1
- package/lib/common/project-layout.js +33 -61
- package/lib/common/project-layout.js.map +1 -1
- package/lib/common/safety.js +2 -3
- package/lib/common/safety.js.map +1 -1
- package/lib/common/template-manifest.js +4 -0
- package/lib/common/template-manifest.js.map +1 -1
- package/lib/common/verifier.js +21 -35
- package/lib/common/verifier.js.map +1 -1
- package/lib/common/workspace-contract.js +57 -23
- package/lib/common/workspace-contract.js.map +1 -1
- package/lib/config/vite-lib.js +1 -1
- package/lib/config/vite-lib.js.map +1 -1
- package/lib/index.js +33 -10
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/create/.gitignore.tpl +28 -8
- package/templates/create/AGENTS.md +75 -45
- package/templates/create/README.md +44 -11
- package/templates/create/package.json +2 -1
- package/templates/lib/.gitignore.tpl +31 -1
- package/templates/lib/.gitlab-ci.yml +2 -2
- package/templates/lib/README.md +24 -1
- package/templates/lib/{test → components/__tests__}/index.spec.ts +1 -1
- package/templates/lib/{test → components/__tests__}/index.spec.tsx +2 -2
- package/templates/lib/farris.config.mjs +2 -2
- package/templates/lib/package.json +1 -1
- package/templates/lib/tsconfig.json +1 -2
- package/templates/lib/vitest.config.ts +4 -2
- package/templates/micro/.eslintrc.cjs +15 -0
- package/templates/micro/.gitignore.tpl +33 -0
- package/templates/micro/.gitlab-ci.yml +59 -0
- package/templates/micro/.prettierrc.json +8 -0
- package/templates/micro/farris.config.mjs +34 -0
- package/templates/micro/index.html +12 -0
- package/templates/micro/mock/README.md +40 -0
- package/templates/micro/package.json +46 -0
- package/templates/micro/src/App.tsx +25 -0
- package/templates/micro/src/locales/index.ts +5 -0
- package/templates/micro/src/main.ts +47 -0
- package/templates/micro/src/router/index.ts +24 -0
- package/templates/micro/src/views/AboutView.tsx +12 -0
- package/templates/micro/src/views/HomeView.tsx +13 -0
- package/templates/micro/src/views/__tests__/AboutView.spec.tsx +11 -0
- package/templates/micro/src/views/__tests__/HomeView.spec.tsx +11 -0
- package/templates/micro/tsconfig.json +18 -0
- package/templates/micro/vitest.config.ts +12 -0
- package/templates/mobile/.gitignore.tpl +25 -24
- package/templates/mobile/farris.config.mjs +2 -2
- package/templates/mobile/mock/README.md +10 -4
- package/templates/mobile/package.json +4 -2
- package/templates/mobile/src/locales/index.ts +2 -2
- package/templates/mobile/src/main.ts +5 -40
- package/templates/mobile/src/views/HomeView.tsx +2 -2
- package/templates/mobile/src/views/__tests__/AboutView.spec.tsx +11 -0
- package/templates/mobile/src/views/__tests__/HomeView.spec.tsx +11 -0
- package/templates/mobile/tsconfig.json +1 -2
- package/templates/mobile/vitest.config.ts +4 -2
- package/templates/web/.gitignore.tpl +25 -24
- package/templates/web/farris.config.mjs +2 -2
- package/templates/web/mock/README.md +10 -4
- package/templates/web/package.json +4 -2
- package/templates/web/src/App.tsx +0 -4
- package/templates/web/src/locales/index.ts +2 -2
- package/templates/web/src/locales/zh-CHS.json +1 -0
- package/templates/web/src/main.ts +5 -40
- package/templates/web/src/views/HomeView.tsx +2 -2
- package/templates/web/src/views/__tests__/AboutView.spec.tsx +11 -0
- package/templates/web/src/views/__tests__/HomeView.spec.tsx +11 -0
- package/templates/web/tsconfig.json +1 -2
- package/templates/web/vitest.config.ts +4 -2
- package/templates/mobile/src/components/TheButton.tsx +0 -9
- package/templates/mobile/test/src/components/TheButton.spec.ts +0 -15
- package/templates/mobile/test/src/components/TheButton.spec.tsx +0 -15
- package/templates/web/src/components/TheButton.tsx +0 -9
- package/templates/web/src/micro-app.d.ts +0 -20
- package/templates/web/src/styles/index.css +0 -0
- package/templates/web/test/src/components/TheButton.spec.ts +0 -15
- package/templates/web/test/src/components/TheButton.spec.tsx +0 -15
- /package/templates/{mobile/src/locales/zh-CN.json → micro/src/locales/zh-CHS.json} +0 -0
- /package/templates/{web → micro}/src/micro/context.ts +0 -0
- /package/templates/{mobile → micro}/src/micro-app.d.ts +0 -0
- /package/templates/{mobile/src/styles/index.css → micro/src/styles/index.scss} +0 -0
- /package/templates/{web/src/locales/zh-CN.json → mobile/src/locales/zh-CHS.json} +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
image: registry.inspures.com/public/docker.io/library/node:22
|
|
2
|
+
|
|
3
|
+
variables:
|
|
4
|
+
NPM_REGISTRY: "https://repos.iec.io/repository/npm-igix/"
|
|
5
|
+
NPM_RELEASE_REGISTRY: "https://repos.iec.io/repository/npm-igix-release/"
|
|
6
|
+
|
|
7
|
+
stages:
|
|
8
|
+
- build
|
|
9
|
+
- publishproject
|
|
10
|
+
|
|
11
|
+
build-job:
|
|
12
|
+
stage: build
|
|
13
|
+
tags:
|
|
14
|
+
- environment:cloud
|
|
15
|
+
before_script:
|
|
16
|
+
- |
|
|
17
|
+
if [ -z "${ARTIFACTS_REPO_USERNAME}" ] || [ -z "${ARTIFACTS_REPO_PASSWORD}" ]; then
|
|
18
|
+
echo "ARTIFACTS_REPO_USERNAME or ARTIFACTS_REPO_PASSWORD is empty on ${CI_COMMIT_REF_NAME}."
|
|
19
|
+
echo "If these GitLab CI/CD variables are Protected, they are not available on unprotected branches."
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
- if [ ! -f .npmrc ]; then wget -O - https://repos.iec.io/gitlab-ci/template/experimental/script/npmrc | sh; fi
|
|
23
|
+
- echo _auth=$(echo -n ${ARTIFACTS_REPO_USERNAME}:${ARTIFACTS_REPO_PASSWORD} | base64) >> .npmrc
|
|
24
|
+
- echo always-auth=true >> .npmrc
|
|
25
|
+
- sed -i "s#registry=.*#registry=$NPM_REGISTRY#g" $CI_PROJECT_DIR/.npmrc
|
|
26
|
+
- cp .npmrc ~/
|
|
27
|
+
- npm config fix
|
|
28
|
+
script:
|
|
29
|
+
- npm i --no-package-lock
|
|
30
|
+
- npm test
|
|
31
|
+
- npm run build
|
|
32
|
+
artifacts:
|
|
33
|
+
expire_in: '5days'
|
|
34
|
+
name: 'dist'
|
|
35
|
+
paths:
|
|
36
|
+
- $CI_PROJECT_DIR/dist
|
|
37
|
+
|
|
38
|
+
publish-project:
|
|
39
|
+
stage: publishproject
|
|
40
|
+
tags:
|
|
41
|
+
- environment:cloud
|
|
42
|
+
rules:
|
|
43
|
+
- if: $CI_COMMIT_TAG =~ /^v\d/
|
|
44
|
+
before_script:
|
|
45
|
+
- |
|
|
46
|
+
if [ -z "${ARTIFACTS_REPO_USERNAME}" ] || [ -z "${ARTIFACTS_REPO_PASSWORD}" ]; then
|
|
47
|
+
echo "ARTIFACTS_REPO_USERNAME or ARTIFACTS_REPO_PASSWORD is empty on ${CI_COMMIT_REF_NAME}."
|
|
48
|
+
echo "If these GitLab CI/CD variables are Protected, they are not available on unprotected branches."
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
- if [ ! -f .npmrc ]; then wget -O - https://repos.iec.io/gitlab-ci/template/experimental/script/npmrc | sh; fi
|
|
52
|
+
- echo _auth=$(echo -n ${ARTIFACTS_REPO_USERNAME}:${ARTIFACTS_REPO_PASSWORD} | base64) >> .npmrc
|
|
53
|
+
- echo always-auth=true >> .npmrc
|
|
54
|
+
- sed -i "s#registry=.*#registry=$NPM_RELEASE_REGISTRY#g" $CI_PROJECT_DIR/.npmrc
|
|
55
|
+
- cp .npmrc ~/
|
|
56
|
+
- npm config fix
|
|
57
|
+
script:
|
|
58
|
+
- npm config set //repos.iec.io/repository/npm-igix-release/:_auth=$(echo -n ${ARTIFACTS_REPO_USERNAME}:${ARTIFACTS_REPO_PASSWORD} | base64)
|
|
59
|
+
- cd dist && npm publish
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
// 相对路径 base:微前端(IBP)与 iframe 嵌入场景都适用
|
|
5
|
+
base: './',
|
|
6
|
+
routerMode: 'hash',
|
|
7
|
+
// 微应用交付:默认 iife 单文件(IBP 微前端);需要普通 ESM 产物时执行 pnpm build:es
|
|
8
|
+
format: "<%= format %>",
|
|
9
|
+
// 输出目录 App/Lib 模式默认值均为 './dist'
|
|
10
|
+
// outDir: fileURLToPath(new URL('./dist', import.meta.url)),
|
|
11
|
+
// 最小化 默认值 true
|
|
12
|
+
minify: true,
|
|
13
|
+
// 外部依赖排除项 默认值 { include: [], exclude: [] }
|
|
14
|
+
// externals: {
|
|
15
|
+
// include: [],
|
|
16
|
+
// exclude: []
|
|
17
|
+
// },
|
|
18
|
+
// 是否排除 package.json 中 dependencies和 peerDependencies 依赖的包; App模式默认值 false Lib模式默认值 true
|
|
19
|
+
externalDependencies: false,
|
|
20
|
+
// 路径别名 默认值 null
|
|
21
|
+
alias: [
|
|
22
|
+
{ find: '@', replacement: fileURLToPath(new URL('./src', import.meta.url)) }
|
|
23
|
+
],
|
|
24
|
+
// 插件 默认值 [vue(), vueJsx()] 不要重复添加
|
|
25
|
+
// plugins: [],
|
|
26
|
+
// 开发期 mock 默认开启:接口数据来自工程内 mock/ 目录,未命中的请求按下方 proxy 转发
|
|
27
|
+
// mock: true,
|
|
28
|
+
// 开发代理:未命中 mock 的接口转发到真实后端;联调时执行 pnpm dev --no-mock 可整体关闭 mock
|
|
29
|
+
// proxy: {
|
|
30
|
+
// '/api': { target: 'http://localhost:8080', changeOrigin: true }
|
|
31
|
+
// },
|
|
32
|
+
// viteConfig 配置项
|
|
33
|
+
viteConfig: {}
|
|
34
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title><%= title %></title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# mock 目录
|
|
2
|
+
|
|
3
|
+
开发期接口数据。一个领域一个文件,命名 `*.mock.ts`,默认导出路由数组:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
export default [
|
|
7
|
+
{
|
|
8
|
+
url: '/api/v1/users', // 必须与代码中的请求路径逐字一致
|
|
9
|
+
method: 'GET', // 默认 GET
|
|
10
|
+
timeout: 300, // 可选 模拟延迟毫秒
|
|
11
|
+
status: 200, // 可选 响应状态码
|
|
12
|
+
response: ({ query, params, body }) => ({
|
|
13
|
+
data: [],
|
|
14
|
+
total: 0
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 加一条 mock 并验证
|
|
21
|
+
|
|
22
|
+
1. 先在 `src/api/` 里确认请求路径(例如 `/api/v1/users`),逐字抄进 `url`。
|
|
23
|
+
2. 新建或追加 `mock/<领域>.mock.ts`,按上面的形状写 `url` / `method` / `response`。
|
|
24
|
+
3. 在工程目录执行 `pnpm dev`,打开用到该接口的页面,**验证**返回的是 mock 数据。
|
|
25
|
+
4. 需要联调真实后端时:`pnpm dev --no-mock`(或 `MOCK=none pnpm dev`),业务代码不改。
|
|
26
|
+
|
|
27
|
+
## 规则
|
|
28
|
+
|
|
29
|
+
- url 必须与代码中的请求路径逐字一致,见 `src/api/` 下的接口模块。
|
|
30
|
+
- 路径参数在 url 里用 `:参数名` 表示,例如 `/api/v1/users/:id`;查询参数不写进 url,在 response 的 `query` 里读取。
|
|
31
|
+
- mock 响应体必须能被工程的 HTTP 客户端正确消费,形状跟着客户端出口走。
|
|
32
|
+
- 同一 url 不允许在多个 mock 文件中重复定义,重复时开发服务启动即报错。
|
|
33
|
+
- mock 只用于开发期:不进构建产物,也不要在组件里散落假数据。
|
|
34
|
+
|
|
35
|
+
## 行为与开关
|
|
36
|
+
|
|
37
|
+
- 命中 mock → 返回 mock 数据。
|
|
38
|
+
- 未命中 → 按 `farris.config.mjs` 的 `proxy` 配置转发真实后端。
|
|
39
|
+
- 未命中且未配代理的 `/api` 路径 → 返回 404 并提示,便于排查漏配。
|
|
40
|
+
- 开关:工程目录内 `pnpm dev` 默认生效;`pnpm dev --no-mock` 或 `MOCK=none pnpm dev` 进真实后端联调。
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= name %>",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"farris": {
|
|
7
|
+
"type": "micro"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "farris-cli dev",
|
|
11
|
+
"build": "farris-cli build -ep --format iife",
|
|
12
|
+
"build:es": "farris-cli build -ep --format es",
|
|
13
|
+
"preview": "farris-cli preview",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest",
|
|
16
|
+
"typecheck": "vue-tsc --noEmit",
|
|
17
|
+
"lint": "eslint . --ext .vue,.ts,.tsx --fix",
|
|
18
|
+
"format": "prettier --write src/",
|
|
19
|
+
"i18n": "farris-cli extract-i18n"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@farris/ui-vue": "latest",
|
|
23
|
+
"vue": "^3.4.29",
|
|
24
|
+
"vue-router": "^4.3.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@farris/cli": "<%= cliVersion %>",
|
|
28
|
+
"@rushstack/eslint-patch": "^1.8.0",
|
|
29
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
|
30
|
+
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
|
31
|
+
"@vue/eslint-config-prettier": "^9.0.0",
|
|
32
|
+
"@vue/eslint-config-typescript": "^13.0.0",
|
|
33
|
+
"@vue/test-utils": "^2.4.6",
|
|
34
|
+
"@vue/tsconfig": "^0.5.1",
|
|
35
|
+
"eslint": "^8.57.0",
|
|
36
|
+
"eslint-plugin-vue": "^9.23.0",
|
|
37
|
+
"jsdom": "^25.0.1",
|
|
38
|
+
"prettier": "^3.2.5",
|
|
39
|
+
"typescript": "~5.4.0",
|
|
40
|
+
"vite": "^5.4.19",
|
|
41
|
+
"vite-plugin-css-injected-by-js": "^3.5.2",
|
|
42
|
+
"vitest": "^3.2.4",
|
|
43
|
+
"vue-tsc": "^2.2.0",
|
|
44
|
+
"sass": "^1.90.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineComponent } from 'vue';
|
|
2
|
+
import { RouterLink, RouterView } from 'vue-router';
|
|
3
|
+
import { setupMicroAppContext } from './micro/context';
|
|
4
|
+
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
name: 'App',
|
|
7
|
+
setup() {
|
|
8
|
+
// 微前端环境:订阅主应用下发的上下文(语言 / 主题)
|
|
9
|
+
setupMicroAppContext();
|
|
10
|
+
|
|
11
|
+
return () => (
|
|
12
|
+
<>
|
|
13
|
+
<header>
|
|
14
|
+
<div class="wrapper">
|
|
15
|
+
<nav>
|
|
16
|
+
<RouterLink to="/">Home</RouterLink>
|
|
17
|
+
<RouterLink to="/about">About</RouterLink>
|
|
18
|
+
</nav>
|
|
19
|
+
</div>
|
|
20
|
+
</header>
|
|
21
|
+
<RouterView />
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createApp, type App as VueApp } from 'vue';
|
|
2
|
+
import FarrisVue from '@farris/ui-vue';
|
|
3
|
+
import '@farris/ui-vue/index.css';
|
|
4
|
+
import App from './App';
|
|
5
|
+
import router from './router';<%= styleImport %>
|
|
6
|
+
import { localResources } from './locales';
|
|
7
|
+
|
|
8
|
+
let app: VueApp | null = null;
|
|
9
|
+
|
|
10
|
+
/** 挂载应用(微前端宿主会调用 window.mount) */
|
|
11
|
+
function mount(): void {
|
|
12
|
+
if (app) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
app = createApp(App);
|
|
16
|
+
app.use(FarrisVue, { basePath: '', locale: 'zh-CHS', localResources });
|
|
17
|
+
app.use(router);
|
|
18
|
+
app.mount('#app');
|
|
19
|
+
|
|
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,24 @@
|
|
|
1
|
+
import { createRouter, createWebHashHistory, type RouteRecordRaw } from 'vue-router';
|
|
2
|
+
|
|
3
|
+
// 生成器(farris-cli generate view --with-route)依赖下面的 routes 数组赋值形式;
|
|
4
|
+
// 改动结构会导致路由无法自动注册。
|
|
5
|
+
export const routes: RouteRecordRaw[] = [
|
|
6
|
+
{
|
|
7
|
+
path: '/',
|
|
8
|
+
name: 'Home',
|
|
9
|
+
component: () => import('../views/HomeView')
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
path: '/about',
|
|
13
|
+
name: 'About',
|
|
14
|
+
component: () => import('../views/AboutView')
|
|
15
|
+
}
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const router = createRouter({
|
|
19
|
+
// hash 路由:微前端(IBP)下子应用 location 由宿主接管,hash 模式最稳妥
|
|
20
|
+
history: createWebHashHistory(),
|
|
21
|
+
routes
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export default router;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import AboutView from '../AboutView';
|
|
4
|
+
|
|
5
|
+
describe('AboutView', () => {
|
|
6
|
+
it('mounts', () => {
|
|
7
|
+
const wrapper = mount(AboutView);
|
|
8
|
+
|
|
9
|
+
expect(wrapper.exists()).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import HomeView from '../HomeView';
|
|
4
|
+
|
|
5
|
+
describe('HomeView', () => {
|
|
6
|
+
it('mounts', () => {
|
|
7
|
+
const wrapper = mount(HomeView);
|
|
8
|
+
|
|
9
|
+
expect(wrapper.exists()).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"env.d.ts",
|
|
5
|
+
"src/**/*",
|
|
6
|
+
"src/**/*.vue"
|
|
7
|
+
],
|
|
8
|
+
"compilerOptions": {
|
|
9
|
+
"composite": true,
|
|
10
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"paths": {
|
|
13
|
+
"@/*": [
|
|
14
|
+
"./src/*"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import vue from '@vitejs/plugin-vue';
|
|
2
|
+
import { configDefaults, defineConfig } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [vue()],
|
|
6
|
+
test: {
|
|
7
|
+
environment: 'jsdom',
|
|
8
|
+
// 官方默认收集范围(**/*.{test,spec}.*),源码旁的测试才会被收集
|
|
9
|
+
include: [...configDefaults.include],
|
|
10
|
+
exclude: [...configDefaults.exclude, '**/__sandbox_*/**']
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
# 依赖与产物
|
|
2
|
+
node_modules/
|
|
3
|
+
dist/
|
|
4
|
+
dist-es/
|
|
5
|
+
dist-ssr/
|
|
6
|
+
coverage/
|
|
7
|
+
*.tsbuildinfo
|
|
8
|
+
.pnpm-store/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
# 日志与本地文件
|
|
11
|
+
*.log
|
|
12
12
|
.DS_Store
|
|
13
|
-
dist
|
|
14
|
-
dist-es
|
|
15
|
-
dist-ssr
|
|
16
|
-
coverage
|
|
17
13
|
*.local
|
|
14
|
+
.env
|
|
15
|
+
.env.*
|
|
16
|
+
!.env.example
|
|
17
|
+
package-lock.json
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
/cypress/screenshots/
|
|
21
|
-
|
|
22
|
-
# Editor directories and files
|
|
19
|
+
# 编辑器
|
|
23
20
|
.vscode/*
|
|
24
21
|
!.vscode/extensions.json
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*.njsproj
|
|
29
|
-
*.sln
|
|
22
|
+
!.vscode/settings.json
|
|
23
|
+
.idea/
|
|
24
|
+
.history
|
|
30
25
|
*.sw?
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
# AI 工具
|
|
28
|
+
.codebuddy/
|
|
29
|
+
.cursor/
|
|
30
|
+
.claude/
|
|
31
|
+
.windsurf/
|
|
32
|
+
.trae/
|
|
33
|
+
.opencode/
|
|
@@ -4,9 +4,9 @@ export default {
|
|
|
4
4
|
// 相对路径 base:微前端(IBP)与 iframe 嵌入场景都适用
|
|
5
5
|
base: './',
|
|
6
6
|
routerMode: 'hash',
|
|
7
|
-
//
|
|
7
|
+
// 默认交付格式;pnpm build 会依次产出 es / umd / systemjs(iife 见 --format iife)
|
|
8
8
|
format: "<%= format %>",
|
|
9
|
-
// 输出目录 App
|
|
9
|
+
// 输出目录 App/Lib 模式默认值均为 './dist'
|
|
10
10
|
// outDir: fileURLToPath(new URL('./dist', import.meta.url)),
|
|
11
11
|
// 最小化 默认值 true
|
|
12
12
|
minify: true,
|
|
@@ -17,7 +17,14 @@ export default [
|
|
|
17
17
|
];
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
## 加一条 mock 并验证
|
|
21
|
+
|
|
22
|
+
1. 先在 `src/api/` 里确认请求路径(例如 `/api/v1/users`),逐字抄进 `url`。
|
|
23
|
+
2. 新建或追加 `mock/<领域>.mock.ts`,按上面的形状写 `url` / `method` / `response`。
|
|
24
|
+
3. 在工程目录执行 `pnpm dev`,打开用到该接口的页面,**验证**返回的是 mock 数据。
|
|
25
|
+
4. 需要联调真实后端时:`pnpm dev --no-mock`(或 `MOCK=none pnpm dev`),业务代码不改。
|
|
26
|
+
|
|
27
|
+
## 规则
|
|
21
28
|
|
|
22
29
|
- url 必须与代码中的请求路径逐字一致,见 `src/api/` 下的接口模块。
|
|
23
30
|
- 路径参数在 url 里用 `:参数名` 表示,例如 `/api/v1/users/:id`;查询参数不写进 url,在 response 的 `query` 里读取。
|
|
@@ -25,10 +32,9 @@ export default [
|
|
|
25
32
|
- 同一 url 不允许在多个 mock 文件中重复定义,重复时开发服务启动即报错。
|
|
26
33
|
- mock 只用于开发期:不进构建产物,也不要在组件里散落假数据。
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
## 行为与开关
|
|
29
36
|
|
|
30
37
|
- 命中 mock → 返回 mock 数据。
|
|
31
38
|
- 未命中 → 按 `farris.config.mjs` 的 `proxy` 配置转发真实后端。
|
|
32
39
|
- 未命中且未配代理的 `/api` 路径 → 返回 404 并提示,便于排查漏配。
|
|
33
|
-
|
|
34
|
-
开关:在工程目录执行 `pnpm dev` 默认生效;`pnpm dev --no-mock` 或 `MOCK=none pnpm dev` 进入真实后端联调。
|
|
40
|
+
- 开关:工程目录内 `pnpm dev` 默认生效;`pnpm dev --no-mock` 或 `MOCK=none pnpm dev` 进真实后端联调。
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "farris-cli dev",
|
|
8
|
-
"build": "
|
|
9
|
-
"build:es": "farris-cli build --format es
|
|
8
|
+
"build": "pnpm run build:es && pnpm run build:umd && pnpm run build:systemjs",
|
|
9
|
+
"build:es": "farris-cli build -ep --format es",
|
|
10
|
+
"build:umd": "farris-cli build -ep --format umd --outDir dist-umd",
|
|
11
|
+
"build:systemjs": "farris-cli build -ep --format systemjs --outDir dist-systemjs",
|
|
10
12
|
"preview": "farris-cli preview",
|
|
11
13
|
"test": "vitest run",
|
|
12
14
|
"test:watch": "vitest",
|
|
@@ -1,47 +1,12 @@
|
|
|
1
|
-
import { createApp
|
|
1
|
+
import { createApp } from 'vue';
|
|
2
2
|
import FarrisVue from '@farris/mobile-ui-vue';
|
|
3
3
|
import '@farris/mobile-ui-vue/style.css';
|
|
4
4
|
import App from './App';
|
|
5
5
|
import router from './router';<%= styleImport %>
|
|
6
6
|
import { localResources } from './locales';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const app = createApp(App);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
app = createApp(App);
|
|
16
|
-
app.use(FarrisVue, { basePath: '', locale: 'zh-CN', localResources });
|
|
17
|
-
app.use(router);
|
|
18
|
-
app.mount('#app');
|
|
19
|
-
|
|
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
|
-
}
|
|
10
|
+
app.use(FarrisVue, { basePath: '', locale: 'zh-CHS', localResources });
|
|
11
|
+
app.use(router);
|
|
12
|
+
app.mount('#app');
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { defineComponent } from 'vue';
|
|
2
|
-
import TheButton from '../components/TheButton';
|
|
3
2
|
|
|
4
3
|
export default defineComponent({
|
|
5
4
|
name: 'HomeView',
|
|
6
5
|
setup() {
|
|
7
6
|
return () => (
|
|
8
7
|
<main>
|
|
9
|
-
<
|
|
8
|
+
<h1>Home</h1>
|
|
9
|
+
<p>在 src/views/ 下新增页面;通用组件按需创建在 src/components/ 下。</p>
|
|
10
10
|
</main>
|
|
11
11
|
);
|
|
12
12
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import AboutView from '../AboutView';
|
|
4
|
+
|
|
5
|
+
describe('AboutView', () => {
|
|
6
|
+
it('mounts', () => {
|
|
7
|
+
const wrapper = mount(AboutView);
|
|
8
|
+
|
|
9
|
+
expect(wrapper.exists()).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import HomeView from '../HomeView';
|
|
4
|
+
|
|
5
|
+
describe('HomeView', () => {
|
|
6
|
+
it('mounts', () => {
|
|
7
|
+
const wrapper = mount(HomeView);
|
|
8
|
+
|
|
9
|
+
expect(wrapper.exists()).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import vue from '@vitejs/plugin-vue';
|
|
2
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import { configDefaults, defineConfig } from 'vitest/config';
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
5
|
plugins: [vue()],
|
|
6
6
|
test: {
|
|
7
7
|
environment: 'jsdom',
|
|
8
|
-
|
|
8
|
+
// 官方默认收集范围(**/*.{test,spec}.*),源码旁的测试才会被收集
|
|
9
|
+
include: [...configDefaults.include],
|
|
10
|
+
exclude: [...configDefaults.exclude, '**/__sandbox_*/**']
|
|
9
11
|
}
|
|
10
12
|
});
|