mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-07 13:28:38 +08:00
refactor: 环境变量 VITE_APP_DISABLE_DEVTOOL 改成用 vite 插件的方式注入代码中
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
<script setup lang="ts">
|
||||
import DisableDevtool from 'disable-devtool'
|
||||
import hotkeys from 'hotkeys-js'
|
||||
import eventBus from './utils/eventBus'
|
||||
import Provider from './ui-provider/index.vue'
|
||||
@@ -65,8 +64,6 @@ onMounted(() => {
|
||||
eventBus.emit('global-system-info-toggle')
|
||||
})
|
||||
})
|
||||
|
||||
import.meta.env.VITE_APP_DISABLE_DEVTOOL === 'true' && DisableDevtool()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ export default async ({ mode, command }) => {
|
||||
}
|
||||
})
|
||||
return defineConfig({
|
||||
// 开发服务器选项 https://cn.vitejs.dev/config/#server-options
|
||||
// 开发服务器选项 https://cn.vitejs.dev/config/server-options
|
||||
server: {
|
||||
open: true,
|
||||
port: 9000,
|
||||
@@ -29,7 +29,7 @@ export default async ({ 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',
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Plugin } from 'vite'
|
||||
export default function createDebugTool(env): Plugin {
|
||||
const { VITE_APP_DEBUG_TOOL } = env
|
||||
return {
|
||||
name: 'debug-plugin',
|
||||
name: 'debug-tool',
|
||||
transform: (code, id) => {
|
||||
if (/src\/main.ts$/.test(id)) {
|
||||
if (VITE_APP_DEBUG_TOOL === 'eruda') {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
export default function createDisableDevtool(env): Plugin {
|
||||
const { VITE_APP_DISABLE_DEVTOOL } = env
|
||||
return {
|
||||
name: 'disable-devtool',
|
||||
transform: (code, id) => {
|
||||
if (/src\/main.ts$/.test(id)) {
|
||||
if (VITE_APP_DISABLE_DEVTOOL === 'true') {
|
||||
code = code.concat(`
|
||||
import DisableDevtool from 'disable-devtool'
|
||||
DisableDevtool()
|
||||
`)
|
||||
}
|
||||
return {
|
||||
code,
|
||||
map: null,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import createArchiver from './archiver'
|
||||
import createConsole from './console'
|
||||
import createBanner from './banner'
|
||||
import createDebugTool from './debug-tool'
|
||||
import createDisableDevtool from './disable-devtool'
|
||||
|
||||
export default function createVitePlugins(viteEnv, isBuild = false) {
|
||||
const vitePlugins: (PluginOption | PluginOption[])[] = [
|
||||
@@ -44,5 +45,6 @@ export default function createVitePlugins(viteEnv, isBuild = false) {
|
||||
vitePlugins.push(createConsole())
|
||||
vitePlugins.push(createBanner())
|
||||
vitePlugins.push(createDebugTool(viteEnv))
|
||||
vitePlugins.push(createDisableDevtool(viteEnv))
|
||||
return vitePlugins
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user