diff --git a/src/App.vue b/src/App.vue index 57d3e16..02c233c 100755 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,4 @@ diff --git a/vite.config.ts b/vite.config.ts index 1b51fd4..4ace21e 100755 --- a/vite.config.ts +++ b/vite.config.ts @@ -16,7 +16,7 @@ export default ({ mode, command }) => { }) return defineConfig({ base: './', - // 开发服务器选项 https://cn.vitejs.dev/config/#server-options + // 开发服务器选项 https://cn.vitejs.dev/config/server-options server: { open: true, port: 9000, @@ -28,7 +28,7 @@ export default ({ mode, command }) => { }, }, }, - // 构建选项 https://cn.vitejs.dev/config/#server-fsserve-root + // 构建选项 https://cn.vitejs.dev/config/build-options build: { outDir: mode === 'production' ? 'dist' : `dist-${mode}`, sourcemap: env.VITE_BUILD_SOURCEMAP === 'true', diff --git a/vite/plugins/debug-tool.ts b/vite/plugins/debug-tool.ts new file mode 100644 index 0000000..aa41c52 --- /dev/null +++ b/vite/plugins/debug-tool.ts @@ -0,0 +1,28 @@ +import type { Plugin } from 'vite' + +export default function createDebugTool(env): Plugin { + const { VITE_APP_DEBUG_TOOL } = env + return { + name: 'debug-plugin', + transform: (code, id) => { + if (/src\/main.ts$/.test(id)) { + if (VITE_APP_DEBUG_TOOL === 'eruda') { + code = code.concat(` + import eruda from 'eruda' + eruda.init() + `) + } + else if (VITE_APP_DEBUG_TOOL === 'vconsole') { + code = code.concat(` + import VConsole from 'vconsole' + new VConsole() + `) + } + return { + code, + map: null, + } + } + }, + } +} diff --git a/vite/plugins/index.ts b/vite/plugins/index.ts index e171a26..22005af 100755 --- a/vite/plugins/index.ts +++ b/vite/plugins/index.ts @@ -14,6 +14,7 @@ import createCompression from './compression' import createArchiver from './archiver' import createConsole from './console' import createBanner from './banner' +import createDebugTool from './debug-tool' export default function createVitePlugins(viteEnv, isBuild = false) { const vitePlugins: (PluginOption | PluginOption[])[] = [ @@ -36,5 +37,6 @@ export default function createVitePlugins(viteEnv, isBuild = false) { vitePlugins.push(createArchiver(viteEnv)) vitePlugins.push(createConsole()) vitePlugins.push(createBanner()) + vitePlugins.push(createDebugTool(viteEnv)) return vitePlugins }