From a14550eca1955e0cc57775bde8572fb70a2ff23e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E5=AF=B8=E7=81=B0?= Date: Wed, 30 Apr 2025 16:31:02 +0800 Subject: [PATCH] feat(projects): :sparkles: support vite devtools specify the editor by launchEditor option. --- .env | 6 +++++- build/plugins/devtools.ts | 9 +++++++++ build/plugins/index.ts | 4 ++-- src/typings/vite-env.d.ts | 4 ++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 build/plugins/devtools.ts diff --git a/.env b/.env index 1eb3205..ef2fba1 100644 --- a/.env +++ b/.env @@ -53,4 +53,8 @@ VITE_STORAGE_PREFIX=SOY_ VITE_AUTOMATICALLY_DETECT_UPDATE=Y # show proxy url log in terminal -VITE_PROXY_LOG=Y \ No newline at end of file +VITE_PROXY_LOG=Y + +# used to control whether to launch editor +# by the way, this plugin is only available in dev mode, not in build mode +VITE_DEVTOOLS_LAUNCH_EDITOR=code \ No newline at end of file diff --git a/build/plugins/devtools.ts b/build/plugins/devtools.ts new file mode 100644 index 0000000..34c08d1 --- /dev/null +++ b/build/plugins/devtools.ts @@ -0,0 +1,9 @@ +import VueDevtools from 'vite-plugin-vue-devtools'; + +export function setupDevtoolsPlugin(viteEnv: Env.ImportMeta) { + const { VITE_DEVTOOLS_LAUNCH_EDITOR } = viteEnv; + + return VueDevtools({ + launchEditor: VITE_DEVTOOLS_LAUNCH_EDITOR + }); +} diff --git a/build/plugins/index.ts b/build/plugins/index.ts index 52c7275..1243fc2 100644 --- a/build/plugins/index.ts +++ b/build/plugins/index.ts @@ -1,18 +1,18 @@ import type { PluginOption } from 'vite'; import vue from '@vitejs/plugin-vue'; import vueJsx from '@vitejs/plugin-vue-jsx'; -import VueDevtools from 'vite-plugin-vue-devtools'; import progress from 'vite-plugin-progress'; import { setupElegantRouter } from './router'; import { setupUnocss } from './unocss'; import { setupUnplugin } from './unplugin'; import { setupHtmlPlugin } from './html'; +import { setupDevtoolsPlugin } from './devtools'; export function setupVitePlugins(viteEnv: Env.ImportMeta, buildTime: string) { const plugins: PluginOption = [ vue(), vueJsx(), - VueDevtools(), + setupDevtoolsPlugin(viteEnv), setupElegantRouter(), setupUnocss(viteEnv), ...setupUnplugin(viteEnv), diff --git a/src/typings/vite-env.d.ts b/src/typings/vite-env.d.ts index 66a384f..c90fb2c 100644 --- a/src/typings/vite-env.d.ts +++ b/src/typings/vite-env.d.ts @@ -106,6 +106,10 @@ declare namespace Env { readonly VITE_STORAGE_PREFIX?: string; /** Whether to automatically detect updates after configuring application packaging */ readonly VITE_AUTOMATICALLY_DETECT_UPDATE?: CommonType.YesOrNo; + /** show proxy url log in terminal */ + readonly VITE_PROXY_LOG?: CommonType.YesOrNo; + /** The launch editor */ + readonly VITE_DEVTOOLS_LAUNCH_EDITOR?: import('vite-plugin-vue-devtools').VitePluginVueDevToolsOptions['launchEditor']; } }