diff --git a/src/App.vue b/src/App.vue index 8a4d32d..b665ee0 100755 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,4 @@ 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 a4c0ab4..dcec149 100755 --- a/vite/plugins/index.ts +++ b/vite/plugins/index.ts @@ -16,6 +16,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[])[] = [ @@ -42,5 +43,6 @@ export default function createVitePlugins(viteEnv, isBuild = false) { vitePlugins.push(createArchiver(viteEnv)) vitePlugins.push(createConsole()) vitePlugins.push(createBanner()) + vitePlugins.push(createDebugTool(viteEnv)) return vitePlugins }