Skip to content

Commit

Permalink
chore: ⏪ 修改mock
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuhang committed Feb 22, 2024
1 parent 208ef44 commit 307cf43
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 618 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ VITE_PORT = 20000

# Basic interface address
VITE_API_URL=/api/

VITE_GLOB_APP_TITLE=TEC-VUE-STARTER
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Whether to open mock
VITE_USE_MOCK = true

VITE_ENABLE_ANALYZE = false

# Proxy
VITE_PROXY_HOST=http://127.0.0.1:20001/api
12 changes: 7 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
* @Author: ydfk
* @Date: 2022-04-09 18:52:13
* @LastEditors: ydfk
* @LastEditTime: 2022-11-23 15:14:41
* @LastEditTime: 2024-02-22 16:18:33
-->
<!DOCTYPE html>
<html lang="zh-cn">
<!doctype html>
<html lang="zh-cn" id="htmlRoot">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<title>%VITE_GLOB_APP_TITLE%</title>
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>百工驿工作空间</title>
</head>
<body>
<div id="app"></div>
Expand Down
11 changes: 6 additions & 5 deletions mock/_createProductionServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@
* @Author: ydfk
* @Date: 2021-09-16 21:00:09
* @LastEditors: ydfk
* @LastEditTime: 2022-11-23 15:05:22
* @LastEditTime: 2024-02-22 15:10:18
*/
import { createProdMockServer } from "vite-plugin-mock/es/createProdMockServer";

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

const mockModules: any[] = [];
Object.keys(modules).forEach((key) => {
if (key.includes("/_")) {
return;
}
//@ts-ignore
mockModules.push(...modules[key].default);
mockModules.push(...(modules as Recordable)[key].default);
});

/**
* Used in a production environment. Need to manually import all modules
*/
export function setupProdMockServer() {
createProdMockServer([...mockModules]);
createProdMockServer(mockModules);
}
22 changes: 22 additions & 0 deletions mock/configMockPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* @Description: Copyright (c) ydfk. All rights reserved
* @Author: ydfk
* @Date: 2024-02-22 15:11:23
* @LastEditors: ydfk
* @LastEditTime: 2024-02-22 15:19:27
*/
import { viteMockServe } from "vite-plugin-mock";

export function configMockPlugin({ isBuild }: { isBuild: boolean }) {
return viteMockServe({
ignore: /^_/,
mockPath: "mock",
localEnabled: !isBuild,
prodEnabled: isBuild,
injectCode: `
import { setupProdMockServer } from '../mock/_createProductionServer';
setupProdMockServer();
`,
});
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"scripts": {
"dev:pre": "node ./node_modules/esbuild/install.js",
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"dev:debug": "vite --debug",
"build:only": "rimraf dist && vite build",
"build": "vue-tsc --noEmit --skipLibCheck && rimraf dist && vite build",
"serve": "vite preview",
"type:check": "vue-tsc --noEmit --skipLibCheck",
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
Expand All @@ -21,6 +23,7 @@
"reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf pnpm-lock.yaml && rimraf node_modules && pnpm install",
"analysis": "windicss-analysis",
"cz": "git add . & czg",
"cz:pass": "git add . & czg --no-verify",
"prepare": "husky"
},
"dependencies": {
Expand Down Expand Up @@ -50,7 +53,6 @@
"@typescript-eslint/parser": "^7.0.2",
"@vitejs/plugin-vue": "^5.0.4",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vue-macros/volar": "^0.18.11",
"@vue/compiler-sfc": "^3.4.19",
"autoprefixer": "^10.4.17",
"czg": "^1.8.0",
Expand All @@ -70,7 +72,6 @@
"postcss-scss": "^4.0.9",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"rollup": "4.12.0",
"rollup-plugin-visualizer": "^5.12.0",
"sass": "^1.71.1",
"scss": "^0.2.4",
Expand All @@ -86,10 +87,9 @@
"typescript": "^5.3.3",
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0",
"unplugin-vue-macros": "^2.7.10",
"vite": "^5.1.4",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-mock": "^3.0.1",
"vite-plugin-mock": "2.9.8",
"vite-plugin-svg-icons2": "^1.0.0",
"vue-eslint-parser": "^9.4.2",
"vue-tsc": "^1.8.27"
Expand Down
Loading

0 comments on commit 307cf43

Please sign in to comment.