Skip to content

Commit

Permalink
fix: use vite load env
Browse files Browse the repository at this point in the history
  • Loading branch information
nmsbnmsb1 authored and TinsFox committed Sep 11, 2024
1 parent b6d0c8d commit 4aa380c
Showing 1 changed file with 37 additions and 38 deletions.
75 changes: 37 additions & 38 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { readFileSync } from "node:fs"

import react from "@vitejs/plugin-react-swc"
import { config } from "dotenv"
import { defineConfig } from "vite"
import { defineConfig, loadEnv } from "vite"
import { createHtmlPlugin } from "vite-plugin-html"
import tsconfigPaths from "vite-tsconfig-paths"

Expand All @@ -11,45 +10,45 @@ import { getGitHash } from "./scripts/lib.ts"
const pkg = JSON.parse(readFileSync("package.json", "utf8"))
const readme = readFileSync("README.md", "utf8")

config()
export default defineConfig(({ mode }) => {
const viteEnv = loadEnv(mode, process.cwd(), "")

const { env } = process
const define = {
APP_VERSION: JSON.stringify(pkg.version),
APP_NAME: JSON.stringify(pkg.name),
APP_DEV_CWD: JSON.stringify(process.cwd()),
GIT_COMMIT_SHA: JSON.stringify(
process.env.VERCEL_GIT_COMMIT_SHA || getGitHash(),
),
DEBUG: process.env.DEBUG === "true",
dependencies: JSON.stringify(pkg.dependencies),
devDependencies: JSON.stringify(pkg.devDependencies),
README: JSON.stringify(readme),
pkg: JSON.stringify(pkg),
}

const define = {
APP_VERSION: JSON.stringify(pkg.version),
APP_NAME: JSON.stringify(pkg.name),
APP_DEV_CWD: JSON.stringify(process.cwd()),
GIT_COMMIT_SHA: JSON.stringify(
process.env.VERCEL_GIT_COMMIT_SHA || getGitHash(),
),
DEBUG: process.env.DEBUG === "true",
dependencies: JSON.stringify(pkg.dependencies),
devDependencies: JSON.stringify(pkg.devDependencies),
README: JSON.stringify(readme),
pkg: JSON.stringify(pkg),
}

export default defineConfig({
plugins: [
tsconfigPaths(),
react(),
createHtmlPlugin({
template: "index.html",
inject: {
data: {
title: env.VITE_APP_NAME,
return {
plugins: [
tsconfigPaths(),
react(),
createHtmlPlugin({
template: "index.html",
inject: {
data: {
title: viteEnv.VITE_APP_NAME,
},
},
}),
],
define,
server: {
port: 3000,
proxy: {
"/^api/": {
target: viteEnv.VITE_API_URL,
changeOrigin: true,
},
},
}),
],
define,
server: {
port: 3000,
proxy: {
"/^api/": {
target: process.env.VITE_API_URL,
changeOrigin: true,
},
},
},
}
})

0 comments on commit 4aa380c

Please sign in to comment.