diff --git a/.env.development b/.env.development index 6bbcda6..d6a5e2c 100644 --- a/.env.development +++ b/.env.development @@ -13,5 +13,7 @@ VITE_GLOB_API_URL= # 接口前缀 VITE_GLOB_API_URL_PREFIX=/server +# 虚拟控制台 +VITE_V_CONSOLE=true diff --git a/.env.production b/.env.production index 5e25a52..fdfc2b2 100644 --- a/.env.production +++ b/.env.production @@ -11,6 +11,9 @@ VITE_GLOB_API_URL_PREFIX = /api # 是否删除console VITE_DROP_CONSOLE=true +# 虚拟控制台 +VITE_V_CONSOLE=false + # 是否启用gzip压缩或brotli压缩, 可选: gzip | brotli | none, 如果你需要多种形式,你可以用','来分隔 VITE_BUILD_COMPRESS='none' diff --git a/build/vite/plugin/index.ts b/build/vite/plugin/index.ts index 7e565f8..0d71aa1 100644 --- a/build/vite/plugin/index.ts +++ b/build/vite/plugin/index.ts @@ -1,14 +1,15 @@ +import * as path from 'node:path' import type { PluginOption } from 'vite' import Components from 'unplugin-vue-components/vite' import { VantResolver } from 'unplugin-vue-components/resolvers' import vue from '@vitejs/plugin-vue' import UnoCSS from 'unocss/vite' import AutoImport from 'unplugin-auto-import/vite' +import { viteVConsole } from 'vite-plugin-vconsole' import { configHtmlPlugin } from './html' import { configCompressPlugin } from './compress' import { configVisualizerConfig } from './visualizer' import { configSvgIconsPlugin } from './svgSprite' - /** * 配置 vite 插件 * @param viteEnv vite 环境变量配置文件键值队 object @@ -26,6 +27,13 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { const vitePlugins: (PluginOption | PluginOption[])[] = [ // have to vue(), + viteVConsole({ + entry: path.resolve('src/main.ts'), // 或者可以使用这个配置: [path.resolve('src/main.ts')] + enabled: viteEnv.VITE_V_CONSOLE, // 可自行结合 mode 和 command 进行判断 + config: { + theme: 'dark', + }, + }), // 按需引入VantUi且自动创建组件声明 Components({ dts: true, diff --git a/index.html b/index.html index e0099b1..a93e310 100644 --- a/index.html +++ b/index.html @@ -10,14 +10,15 @@