diff --git a/frontend/README.md b/frontend/README.md index 0e841e0e48..04e409caa7 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -73,10 +73,11 @@ Closes #123 │ │ ├── modules // 各业务模块的请求方法 │ │ ├── requrls // 按业务模块划分的接口地址 │ ├── assets // 全局静态资源 +│ │ ├── font +│ │ ├── icon-font │ │ ├── images - - svg -│ │ ├── logo.svg │ │ ├── style +│ │ ├── svg │ ├── components // 组件 │ ├── config // 全局配置,常量类、JSON │ ├── directive // 自定义指令集 @@ -85,7 +86,6 @@ Closes #123 │ ├── layout // 应用布局组件 │ ├── locale // 国际化配置 │ ├── main.ts // 项目主入口 -│ ├── mock // mock数据配置 │ ├── models // 全局数据模型定义 │ ├── router // 路由 │ ├── store // pinia状态库 @@ -580,7 +580,6 @@ module.exports = { "lib": ["esnext", "dom"], "skipLibCheck": true, // 跳过node依赖包语法检查 "types": [ - // "vitest/globals", // "vite-plugin-svg-icons/client" ], // 手动导入TS类型声明文件 "baseUrl": ".", @@ -706,39 +705,6 @@ export default mergeConfig( ); ``` -## 单元测试 - -测试框架:vitest - -单元测试实用工具库: @vue/test-utils - -测试环境: js-dom - -报告: @vitest/coverage-c8 - -```bash -pnpm add -D vitest @vue/test-utils js-dom @vitest/coverage-c8 -``` - -配置 - -根目录新建 vitest.config.ts - -```typescript -import { mergeConfig } from 'vite'; -import { defineConfig } from 'vitest/config'; -import viteConfig from './config/vite.config.dev'; - -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - environment: 'jsdom', - }, - }) -); -``` - ## 本地生产环境调试 需安装 docker: https://www.docker.com/, 选择对应系统版本安装。 diff --git a/frontend/config/vite.config.dev.ts b/frontend/config/vite.config.dev.ts index 33b139014d..5a86a4c461 100644 --- a/frontend/config/vite.config.dev.ts +++ b/frontend/config/vite.config.dev.ts @@ -1,4 +1,3 @@ -/// import baseConfig from './vite.config.base'; import dotenv from 'dotenv'; import { mergeConfig } from 'vite'; diff --git a/frontend/config/vite.config.prod.ts b/frontend/config/vite.config.prod.ts index afab442ea6..b83f075a40 100644 --- a/frontend/config/vite.config.prod.ts +++ b/frontend/config/vite.config.prod.ts @@ -1,12 +1,20 @@ import configCompressPlugin from './plugin/compress'; import configVisualizerPlugin from './plugin/visualizer'; import baseConfig from './vite.config.base'; +import legacy from '@vitejs/plugin-legacy'; import { mergeConfig } from 'vite'; export default mergeConfig( { mode: 'production', - plugins: [configCompressPlugin('gzip'), configVisualizerPlugin()], + plugins: [ + configCompressPlugin('gzip'), + configVisualizerPlugin(), + // 兼容性配置,配合package.json中的browserslist使用 + legacy({ + targets: ['defaults', 'not IE 11'], + }), + ], build: { rollupOptions: { output: { @@ -14,6 +22,7 @@ export default mergeConfig( vue: ['vue', 'vue-router', 'pinia', '@vueuse/core', 'vue-i18n'], arco: ['@arco-design/web-vue'], chart: ['echarts', 'vue-echarts'], + codeEditor: ['monaco-editor'], }, }, }, diff --git a/frontend/package.json b/frontend/package.json index 861df625a3..22c3ae78d7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "meter-sphere", "description": "MeterSphere FrontEnd", - "version": "3.0.0", + "version": "3.1.0", "private": true, "author": "MeterSphere Team", "license": "MIT", @@ -16,9 +16,7 @@ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix", "lint:styles": "stylelint 'src/**/*.{vue,html,css,scss,less}' --fix", "lint-staged": "npx lint-staged", - "prepare": "cd .. && husky install frontend/.husky", - "test": "vitest", - "coverage": "vitest run --coverage" + "prepare": "cd .. && husky install frontend/.husky" }, "lint-staged": { "*.{js,ts,jsx,tsx}": [ @@ -102,9 +100,9 @@ "@types/sortablejs": "^1.15.8", "@typescript-eslint/eslint-plugin": "^7.15.0", "@typescript-eslint/parser": "^7.15.0", + "@vitejs/plugin-legacy": "^4.1.1", "@vitejs/plugin-vue": "^4.6.2", "@vitejs/plugin-vue-jsx": "^3.1.0", - "@vitest/coverage-c8": "^0.31.4", "@vue/babel-plugin-jsx": "^1.2.2", "@vue/test-utils": "^2.4.6", "autoprefixer": "^10.4.19", @@ -159,15 +157,20 @@ "vite-plugin-svg-icons": "^2.0.1", "vite-plugin-vue-setup-extend": "^0.4.0", "vite-svg-loader": "^3.6.0", - "vitest": "^0.31.4", "vue-tsc": "^1.8.27" }, "engines": { "node": ">=18.0.0" }, + "browserslist": [ + "> 0.5%", + "last 2 versions", + "not dead", + "not IE 11" + ], "resolutions": { "bin-wrapper": "npm:bin-wrapper-china", "rollup": "^4.18.0", "gifsicle": "5.2.0" } -} +} \ No newline at end of file diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index c89fff1f94..974a076666 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -35,7 +35,6 @@ "skipLibCheck": true, // 跳过node依赖包语法检查 "types": [ "node", - // "vitest/globals", // "vite-plugin-svg-icons/client" ], // 手动导入TS类型声明文件 "baseUrl": ".", diff --git a/frontend/vitest.config.ts b/frontend/vitest.config.ts deleted file mode 100644 index 8c666bca04..0000000000 --- a/frontend/vitest.config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import viteConfig from './config/vite.config.dev'; -import { mergeConfig } from 'vite'; -import { defineConfig } from 'vitest/config'; - -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - environment: 'jsdom', - }, - }) -);