Skip to content

Commit

Permalink
feat: 支持环境变量开关Inspect调试
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Mar 3, 2022
1 parent 711b216 commit 7fcbb9d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 通用环境变量

# 标题
VITE_APP_TITLE = Vite App 🦕
VITE_APP_TITLE = Vite App 🦕


# 开发时 Inspect 调试支持,不需要可以关掉以提高开发时性能
VITE_APP_INSPECT = false
4 changes: 4 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@

# 标题
# VITE_APP_TITLE = Vite App 🦕


# 开发时 Inspect 调试支持
# VITE_APP_Inspect = true
21 changes: 21 additions & 0 deletions presets/shared/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { loadEnv } from 'vite'

const { NODE_ENV } = process.env

export const isDevelopment = NODE_ENV === 'development'
export const isProduction = NODE_ENV === 'production'

const generateEnv = () => {
const env = isProduction
? loadEnv('production', '.')
: loadEnv('development', '.')
const newEnv = {
VITE_APP_TITLE: env.VITE_APP_TITLE,
VITE_APP_INSPECT: Boolean(
env.VITE_APP_Inspect === 'true' || false
)
}
return newEnv
}

export const env = generateEnv()
5 changes: 4 additions & 1 deletion presets/tov.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { env } from './shared/env'
import { resolve } from 'path'
import Vue from '@vitejs/plugin-vue'
import Prism from 'markdown-it-prism'
Expand Down Expand Up @@ -61,7 +62,9 @@ export default () => {
// 布局系统
Layouts(),
// 调试工具
Inspect(),
Inspect({
enabled: env.VITE_APP_INSPECT
}),
// windicss 插件
Windicss({
safelist: markdownWrapperClasses
Expand Down

0 comments on commit 7fcbb9d

Please sign in to comment.