app-template/app/web/astro.config.ts

55 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import node from "@astrojs/node";
import react from "@astrojs/react";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "astro/config";
const __dirname = dirname(fileURLToPath(import.meta.url));
// monorepo 根 .env(Astro 默认只读 app/web/.env,SSR 里 @app/db 要 process.env.TURSO_*)
try {
const env = readFileSync(resolve(__dirname, "../../.env"), "utf-8");
for (const line of env.split("\n")) {
const [key, ...vals] = line.split("=");
if (key && !key.startsWith("#")) {
process.env[key.trim()] ??= vals.join("=").trim();
}
}
} catch {}
// SSR + Node standalone;@app/* 别名指向各包 dist(dev/build 前需先 build 上游)
export default defineConfig({
output: "server",
adapter: node({ mode: "standalone" }),
integrations: [react()],
// 路由:动态 [locale]/… 单套视图;/ 与非法前缀在 middleware 处理
vite: {
plugins: [tailwindcss()],
optimizeDeps: {
// 预打包 react CJS,避免浏览器拿裸 CJS 导致 island 无 createRoot
include: ["react", "react-dom", "react-dom/client"],
},
resolve: {
alias: {
"@/*": resolve(__dirname, "src"),
"@app/i18n": resolve(__dirname, "../../packages/i18n/dist/index.js"),
"@app/trpc": resolve(__dirname, "../../packages/trpc/dist/index.js"),
"@app/types": resolve(__dirname, "../../packages/types/dist/index.js"),
"@app/db": resolve(__dirname, "../../packages/db/dist/index.js"),
"@app/seo-geo": resolve(__dirname, "../../packages/seo-geo/dist/index.js"),
"@app/ui": resolve(__dirname, "../../packages/ui/src/index.ts"),
},
dedupe: ["react", "react-dom"],
},
ssr: {
noExternal: ["@app/trpc", "@app/db", "@app/i18n", "@app/ui"],
},
},
server: {
port: 4321,
host: false,
},
});