From 29698bef69ddee728e7bcad2cad18ce1fe57e77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E8=8F=9C=E7=99=BD=E7=8E=89=E6=B1=A4?= <79054161+Azir-11@users.noreply.github.com> Date: Fri, 4 Apr 2025 12:00:52 +0800 Subject: [PATCH] feat(projects): support vite devtools specify the editor by launchEditor option. (#730) --- .env | 4 ++++ build/plugins/devtools.ts | 9 +++++++++ build/plugins/index.ts | 4 ++-- src/typings/vite-env.d.ts | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 build/plugins/devtools.ts diff --git a/.env b/.env index bf5baffe..4b59e331 100644 --- a/.env +++ b/.env @@ -54,3 +54,7 @@ VITE_AUTOMATICALLY_DETECT_UPDATE=Y # show proxy url log in terminal 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 diff --git a/build/plugins/devtools.ts b/build/plugins/devtools.ts new file mode 100644 index 00000000..34c08d1a --- /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 52c72755..1243fc2f 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 d6ba76f6..c90fb2c2 100644 --- a/src/typings/vite-env.d.ts +++ b/src/typings/vite-env.d.ts @@ -108,6 +108,8 @@ declare namespace Env { 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']; } }