Skip to content

Commit

Permalink
feat: add env file
Browse files Browse the repository at this point in the history
  • Loading branch information
kaivanwong committed Dec 5, 2023
1 parent 61e7564 commit 04d08cd
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
Empty file added .vite/constants.ts
Empty file.
2 changes: 2 additions & 0 deletions .vite/env/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_ENV_MODE = development
VITE_BASE_URL = /
2 changes: 2 additions & 0 deletions .vite/env/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_ENV_MODE = production
VITE_BASE_URL = /
2 changes: 2 additions & 0 deletions .vite/env/.env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_ENV_MODE = staging
VITE_BASE_URL = /
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"build": "run-p type-check build-only",
"preview": "vite preview",
"test:unit": "vitest",
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'",
Expand Down
20 changes: 15 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
"extends": "@vue/tsconfig/tsconfig.json",
"compilerOptions": {
"composite": true,
"lib": ["DOM", "ESNext"],
"baseUrl": ".",
"module": "ESNext",
"moduleResolution": "Bundler",
"paths": {
"@/*": ["./src/*"]
"@/*": [
"./src/*"
]
},
"types": ["node", "jsdom"]
"types": [
"vitest",
"vite/client"
],
"allowJs": true,
"strictNullChecks": true,
"noUnusedLocals": true
},
"include": [
"env.d.ts",
Expand All @@ -20,5 +27,8 @@
"nightwatch.conf.*",
"playwright.config.*"
],
"exclude": ["src/**/__tests__/*"]
"exclude": [
"node_modules",
"dist"
]
}
File renamed without changes.
38 changes: 23 additions & 15 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import { URL, fileURLToPath } from 'node:url'
import { type ConfigEnv, defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
export default (options: ConfigEnv) => {
const { mode } = options

const envDir = '.vite/env/'

const env = loadEnv(mode, envDir, ['VITE_', 'APP_', 'AXIOS_'])

return defineConfig({
base: env.VITE_BASE_URL,
envDir,
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
})
}

0 comments on commit 04d08cd

Please sign in to comment.