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']; } }