newsnow/nitro.config.ts

61 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-10-30 15:06:21 +08:00
import process from "node:process"
import { join } from "node:path"
import viteNitro from "vite-plugin-with-nitro"
import { RollopGlob } from "./tools/rollup-glob"
import { projectDir } from "./shared/dir"
const nitroOption: Parameters<typeof viteNitro>[0] = {
experimental: {
database: true,
},
rollupConfig: {
plugins: [RollopGlob()],
},
sourceMap: false,
database: {
default: {
connector: "sqlite",
},
},
imports: {
dirs: ["server/utils", "shared"],
},
preset: "node-server",
alias: {
"@shared": join(projectDir, "shared"),
"#": join(projectDir, "server"),
},
}
if (process.env.VERCEL) {
nitroOption.preset = "vercel-edge"
// You can use other online database, do it yourself. For more info: https://db0.unjs.io/connectors
nitroOption.database = undefined
2024-10-31 14:21:11 +08:00
// nitroOption.vercel = {
// config: {
// cache: []
// },
// }
2024-10-30 15:06:21 +08:00
} else if (process.env.CF_PAGES) {
nitroOption.preset = "cloudflare-pages"
nitroOption.database = {
default: {
connector: "cloudflare-d1",
options: {
2024-10-30 16:12:05 +08:00
bindingName: "NEWSNOW_DB",
2024-10-30 15:06:21 +08:00
},
},
}
} else if (process.env.BUN) {
nitroOption.preset = "bun"
nitroOption.database = {
default: {
connector: "bun-sqlite",
},
}
}
export default function () {
return viteNitro(nitroOption)
}