newsnow/nitro.config.ts
2024-10-30 16:12:05 +08:00

56 lines
1.2 KiB
TypeScript

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
} else if (process.env.CF_PAGES) {
nitroOption.preset = "cloudflare-pages"
nitroOption.database = {
default: {
connector: "cloudflare-d1",
options: {
bindingName: "NEWSNOW_DB",
},
},
}
} else if (process.env.BUN) {
nitroOption.preset = "bun"
nitroOption.database = {
default: {
connector: "bun-sqlite",
},
}
}
export default function () {
return viteNitro(nitroOption)
}