newsnow/vite.config.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-09-26 19:16:42 +08:00
import process from "node:process"
2024-10-03 23:11:10 +08:00
import { join } from "node:path"
2024-09-26 11:30:21 +08:00
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react-swc"
import nitro from "vite-plugin-with-nitro"
import { TanStackRouterVite } from "@tanstack/router-plugin/vite"
import tsconfigPath from "vite-tsconfig-paths"
2024-09-26 19:16:42 +08:00
import unocss from "unocss/vite"
2024-10-14 00:02:58 +08:00
import dotenv from "dotenv"
2024-10-03 23:11:10 +08:00
import { projectDir } from "./shared/dir"
const isCF = process.env.CF_PAGES
2024-09-26 11:30:21 +08:00
2024-10-14 00:02:58 +08:00
dotenv.config({
2024-10-14 17:18:57 +08:00
path: join(projectDir, ".env.server"),
2024-10-14 00:02:58 +08:00
})
2024-09-26 11:30:21 +08:00
export default defineConfig({
2024-10-14 00:02:58 +08:00
define: {
__G_CLIENT_ID__: `"${process.env.G_CLIENT_ID}"`,
2024-10-14 17:18:57 +08:00
__ENABLE_LOGIN__: ["JWT_SECRET", "G_CLIENT_ID", "G_CLIENT_SECRET"].every(k => process.env[k]),
2024-10-14 00:02:58 +08:00
},
2024-09-26 11:30:21 +08:00
plugins: [
TanStackRouterVite({
autoCodeSplitting: true,
}),
2024-09-26 19:16:42 +08:00
unocss(),
2024-09-26 11:30:21 +08:00
tsconfigPath(),
react(),
nitro({ ssr: false }, {
srcDir: "server",
2024-10-03 17:24:29 +08:00
experimental: {
database: true,
},
database: {
default: {
2024-10-11 20:50:09 +08:00
connector: isCF ? "cloudflare-d1" : "sqlite",
2024-10-03 17:24:29 +08:00
options: {
2024-10-14 00:02:58 +08:00
bindingName: "NEWSNOW_DB",
2024-10-03 17:24:29 +08:00
},
},
},
2024-09-29 20:57:24 +08:00
alias: {
2024-10-03 23:11:10 +08:00
"@shared": join(projectDir, "shared"),
"#": join(projectDir, "server"),
2024-09-29 20:57:24 +08:00
},
2024-10-03 23:11:10 +08:00
preset: isCF ? "cloudflare-pages" : "node-server",
2024-09-26 11:30:21 +08:00
}),
],
})