From 4d84d7a55375944ca815cb6f8494cff65753c49b Mon Sep 17 00:00:00 2001 From: chuan_wuhao <443547225@qq.com> Date: Thu, 29 Dec 2022 14:58:28 +0800 Subject: [PATCH] =?UTF-8?q?v3.0.2=E5=8F=91=E5=B8=83=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=96=87=E6=A1=A3=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 3 +- .gitignore | 1 + cfg.ts | 80 +++++++ package.json | 4 +- src/axios/api/test.ts | 2 +- src/components/RayChart/index.tsx | 20 ++ .../RayTransitionComponent/index.vue | 4 +- src/views/echart/index.tsx | 4 +- tsconfig.node.json | 2 +- vite-plugin/index.ts | 202 ++++++------------ vite.config.ts | 29 ++- 11 files changed, 203 insertions(+), 148 deletions(-) create mode 100644 cfg.ts diff --git a/.eslintignore b/.eslintignore index 18151d4a..b3355b99 100644 --- a/.eslintignore +++ b/.eslintignore @@ -8,4 +8,5 @@ public yarn.* vite-env.* .prettierrc.* -.eslintrc \ No newline at end of file +.eslintrc +visualizer.* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 25ad456d..e1775de0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ dist-ssr dist dist/ *.local +visualizer.* # Editor directories and files .vscode diff --git a/cfg.ts b/cfg.ts new file mode 100644 index 00000000..64682f8d --- /dev/null +++ b/cfg.ts @@ -0,0 +1,80 @@ +import path from 'node:path' + +import { HTMLTitlePlugin, buildOptions } from './vite-plugin/index' + +import type { ServerOptions, BuildOptions, AliasOptions } from 'vite' + +export interface HTMLTitle { + name: string + transformIndexHtml: (title: string) => string +} + +export interface Config { + server: ServerOptions + buildOptions: (mode: string) => BuildOptions + alias: AliasOptions + title: HTMLTitle +} + +const config: Config = { + /** + * + * 浏览器标题 + */ + title: HTMLTitlePlugin('ray template'), + /** + * + * 配置 HMR 特定选项(端口、主机、路径和协议) + */ + server: { + host: '0.0.0.0', + port: 9527, + open: false, + https: false, + strictPort: false, + fs: { + strict: false, + allow: [], + }, + proxy: { + '/api': { + target: 'url', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, ''), + }, + }, + }, + /** + * + * 打包相关配置 + */ + buildOptions: buildOptions, + /** + * + * 预设别名 + * - `@`: `src` 根目录 + * - `@use-utils`: `src/utils` 根目录 + * - `@use-api`: `src/axios/api` 根目录 + * - `@use-images`: `src/assets/images` 根目录 + */ + alias: [ + { + find: '@', + replacement: path.resolve(__dirname, './src'), + }, + { + find: '@use-utils', + replacement: path.resolve(__dirname, './src/utils'), + }, + { + find: '@use-api', + replacement: path.resolve(__dirname, './src/axios/api'), + }, + { + find: '@use-images', + replacement: path.resolve(__dirname, './src/assets/images'), + }, + ], +} + +export default config diff --git a/package.json b/package.json index f8c03140..225045cb 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "vue-tsc --noEmit && vite build", "preview": "vite preview", "test": "vue-tsc --noEmit && vite build --mode test", - "dev-build": "vue-tsc --noEmit && vite build --mode development" + "dev-build": "vue-tsc --noEmit && vite build --mode development", + "report": "vue-tsc --noEmit && vite build" }, "dependencies": { "@vueuse/core": "^9.1.0", @@ -54,6 +55,7 @@ "postcss": "^8.1.0", "postcss-pxtorem": "^6.0.0", "prettier": "^2.7.1", + "rollup-plugin-visualizer": "^5.8.3", "svg-sprite-loader": "^6.0.11", "typescript": "*", "unplugin-auto-import": "^0.11.0", diff --git a/src/axios/api/test.ts b/src/axios/api/test.ts index f8a5d2f2..220801aa 100644 --- a/src/axios/api/test.ts +++ b/src/axios/api/test.ts @@ -1,4 +1,4 @@ -import useRequest from '../index' +import useRequest from '@/axios/index' /** * diff --git a/src/components/RayChart/index.tsx b/src/components/RayChart/index.tsx index eac22a25..4109ad95 100644 --- a/src/components/RayChart/index.tsx +++ b/src/components/RayChart/index.tsx @@ -24,6 +24,7 @@ import { cloneDeep } from 'lodash-es' import { on, off } from '@/utils/element' import type { PropType } from 'vue' +import type {} from 'echarts' export type AutoResize = | boolean @@ -150,6 +151,16 @@ const RayChart = defineComponent({ type: Boolean, default: false, }, + use: { + /** + * + * 拓展 `echarts` 图表 + * + * 由于官方并没有提供该类型, 手动去复刻成本过高, 故而采用 `any` + */ + type: Array, + default: () => [], + }, }, setup(props) { const settingStore = useSetting() @@ -194,6 +205,15 @@ const RayChart = defineComponent({ echarts.use([LabelLayout, UniversalTransition]) // 注册布局, 过度效果 echarts.use([props.canvasRender ? CanvasRenderer : SVGRenderer]) // 注册渲染器 + + try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + echarts.use(props.use as any[]) + } catch (e) { + console.error( + 'Error: wrong property and method passed in extend attribute', + ) + } } /** diff --git a/src/components/RayTransitionComponent/index.vue b/src/components/RayTransitionComponent/index.vue index a3d80be3..b14a3f63 100644 --- a/src/components/RayTransitionComponent/index.vue +++ b/src/components/RayTransitionComponent/index.vue @@ -12,13 +12,15 @@