Skip to content

Commit 307cf43

Browse files
author
liyuhang
committed
chore: ⏪ 修改mock
1 parent 208ef44 commit 307cf43

File tree

16 files changed

+378
-618
lines changed

16 files changed

+378
-618
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ VITE_PORT = 20000
33

44
# Basic interface address
55
VITE_API_URL=/api/
6+
7+
VITE_GLOB_APP_TITLE=TEC-VUE-STARTER

.env.development

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Whether to open mock
22
VITE_USE_MOCK = true
33

4+
VITE_ENABLE_ANALYZE = false
5+
46
# Proxy
57
VITE_PROXY_HOST=http://127.0.0.1:20001/api

index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
* @Author: ydfk
44
* @Date: 2022-04-09 18:52:13
55
* @LastEditors: ydfk
6-
* @LastEditTime: 2022-11-23 15:14:41
6+
* @LastEditTime: 2024-02-22 16:18:33
77
-->
8-
<!DOCTYPE html>
9-
<html lang="zh-cn">
8+
<!doctype html>
9+
<html lang="zh-cn" id="htmlRoot">
1010
<head>
1111
<meta charset="UTF-8" />
12+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
13+
<meta name="renderer" content="webkit" />
14+
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" />
15+
<title>%VITE_GLOB_APP_TITLE%</title>
1216
<link rel="icon" href="/favicon.ico" />
13-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
14-
<title>百工驿工作空间</title>
1517
</head>
1618
<body>
1719
<div id="app"></div>

mock/_createProductionServer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
* @Author: ydfk
44
* @Date: 2021-09-16 21:00:09
55
* @LastEditors: ydfk
6-
* @LastEditTime: 2022-11-23 15:05:22
6+
* @LastEditTime: 2024-02-22 15:10:18
77
*/
88
import { createProdMockServer } from "vite-plugin-mock/es/createProdMockServer";
99

10-
//@ts-ignore
1110
const modules = import.meta.glob("./**/*.ts", { eager: true });
1211

1312
const mockModules: any[] = [];
1413
Object.keys(modules).forEach((key) => {
1514
if (key.includes("/_")) {
1615
return;
1716
}
18-
//@ts-ignore
19-
mockModules.push(...modules[key].default);
17+
mockModules.push(...(modules as Recordable)[key].default);
2018
});
2119

20+
/**
21+
* Used in a production environment. Need to manually import all modules
22+
*/
2223
export function setupProdMockServer() {
23-
createProdMockServer([...mockModules]);
24+
createProdMockServer(mockModules);
2425
}

mock/configMockPlugin.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Description: Copyright (c) ydfk. All rights reserved
3+
* @Author: ydfk
4+
* @Date: 2024-02-22 15:11:23
5+
* @LastEditors: ydfk
6+
* @LastEditTime: 2024-02-22 15:19:27
7+
*/
8+
import { viteMockServe } from "vite-plugin-mock";
9+
10+
export function configMockPlugin({ isBuild }: { isBuild: boolean }) {
11+
return viteMockServe({
12+
ignore: /^_/,
13+
mockPath: "mock",
14+
localEnabled: !isBuild,
15+
prodEnabled: isBuild,
16+
injectCode: `
17+
import { setupProdMockServer } from '../mock/_createProductionServer';
18+
19+
setupProdMockServer();
20+
`,
21+
});
22+
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"scripts": {
1010
"dev:pre": "node ./node_modules/esbuild/install.js",
1111
"dev": "vite",
12-
"build": "vue-tsc --noEmit && vite build",
12+
"dev:debug": "vite --debug",
13+
"build:only": "rimraf dist && vite build",
14+
"build": "vue-tsc --noEmit --skipLibCheck && rimraf dist && vite build",
1315
"serve": "vite preview",
1416
"type:check": "vue-tsc --noEmit --skipLibCheck",
1517
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
@@ -21,6 +23,7 @@
2123
"reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf pnpm-lock.yaml && rimraf node_modules && pnpm install",
2224
"analysis": "windicss-analysis",
2325
"cz": "git add . & czg",
26+
"cz:pass": "git add . & czg --no-verify",
2427
"prepare": "husky"
2528
},
2629
"dependencies": {
@@ -50,7 +53,6 @@
5053
"@typescript-eslint/parser": "^7.0.2",
5154
"@vitejs/plugin-vue": "^5.0.4",
5255
"@vitejs/plugin-vue-jsx": "^3.1.0",
53-
"@vue-macros/volar": "^0.18.11",
5456
"@vue/compiler-sfc": "^3.4.19",
5557
"autoprefixer": "^10.4.17",
5658
"czg": "^1.8.0",
@@ -70,7 +72,6 @@
7072
"postcss-scss": "^4.0.9",
7173
"prettier": "^3.2.5",
7274
"rimraf": "^5.0.5",
73-
"rollup": "4.12.0",
7475
"rollup-plugin-visualizer": "^5.12.0",
7576
"sass": "^1.71.1",
7677
"scss": "^0.2.4",
@@ -86,10 +87,9 @@
8687
"typescript": "^5.3.3",
8788
"unplugin-auto-import": "^0.17.5",
8889
"unplugin-vue-components": "^0.26.0",
89-
"unplugin-vue-macros": "^2.7.10",
9090
"vite": "^5.1.4",
9191
"vite-plugin-compression": "^0.5.1",
92-
"vite-plugin-mock": "^3.0.1",
92+
"vite-plugin-mock": "2.9.8",
9393
"vite-plugin-svg-icons2": "^1.0.0",
9494
"vue-eslint-parser": "^9.4.2",
9595
"vue-tsc": "^1.8.27"

0 commit comments

Comments
 (0)