Skip to content

Commit

Permalink
chore: config env by dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW committed Aug 18, 2023
1 parent aac3106 commit 005de26
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ENABLE_INJECT_ANALYTICS=false

BASE_URL=app
PPD_HEADER_JUMP_URL=https://github.com/power-playground/app
2 changes: 2 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Define to control vite
PPD_CONFIGURE_PATH=mock/.ppd.client.configure.ts
Empty file added .env.pro
Empty file.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
stats.html

# Envrioment
.env
.env.local

# Logs
logs
Expand Down
13 changes: 13 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import inspect from 'vite-plugin-inspect'
import replacer from './vite-plugins/replacer'

configDotenv()
configDotenv({
path: path.resolve(process.cwd(), '.env.local')
})
const { NODE_ENV } = process.env
if (NODE_ENV === undefined) {
console.warn('NODE_ENV not set, use "development" as default.')
process.env.NODE_ENV = 'development'
}
configDotenv({
path: path.resolve(process.cwd(), `.env.${
NODE_ENV === 'development' ? 'dev' : 'pro'
}`)
})

function relative(prev: '__DONT_USE_DIRNAME_AS_YOUR_DIRECTORY_NAME__' | (string & {}), p: string) {
const np = path.relative(
Expand Down

0 comments on commit 005de26

Please sign in to comment.