mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-13 19:20:04 +00:00
📦 build(server): self-contained dev/start entry for @lobechat/server
- add pnpm dev (vite-node watch, loads repo-root .env via new src/hono/dev.ts) and pnpm start (node dist/standalone.js) scripts - move viteNodeServer/viteHonoBuild configs from scripts/ into apps/server - root dev:hono:server now delegates to pnpm --filter @lobechat/server dev
This commit is contained in:
@@ -4,10 +4,15 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "vite build --config ../../scripts/viteHonoBuild.config.ts",
|
||||
"build": "vite build --config viteHonoBuild.config.ts",
|
||||
"dev": "vite-node --watch --config viteNodeServer.config.ts src/hono/dev.ts",
|
||||
"start": "node dist/standalone.js",
|
||||
"type-check": "tsc --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "8.0.14"
|
||||
"dotenv": "^17.2.3",
|
||||
"dotenv-expand": "^12.0.3",
|
||||
"vite": "8.0.14",
|
||||
"vite-node": "3.2.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
import dotenvExpand from 'dotenv-expand';
|
||||
|
||||
// Standalone dev entry: load the repo-root .env files (shell env wins, same
|
||||
// precedence as scripts/devHonoLite.mts) before the server module evaluates.
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
const rootEnvPath = (file: string) =>
|
||||
fileURLToPath(new URL(`../../../../${file}`, import.meta.url));
|
||||
|
||||
const shellEnv = Object.entries(process.env).reduce<Record<string, string>>((acc, [key, value]) => {
|
||||
if (typeof value === 'string') acc[key] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
const dotenvEnv: Record<string, string> = {};
|
||||
const dotenvResult = dotenv.config({
|
||||
override: true,
|
||||
path: [rootEnvPath('.env'), rootEnvPath(`.env.${env}`), rootEnvPath(`.env.${env}.local`)],
|
||||
processEnv: dotenvEnv,
|
||||
});
|
||||
|
||||
if (dotenvResult.parsed) {
|
||||
const expanded = dotenvExpand.expand({
|
||||
parsed: dotenvResult.parsed,
|
||||
processEnv: { ...dotenvEnv, ...shellEnv },
|
||||
});
|
||||
|
||||
Object.assign(process.env, expanded.parsed, shellEnv);
|
||||
}
|
||||
|
||||
(process.env as Record<string, string | undefined>).NODE_ENV ||= 'development';
|
||||
|
||||
await import('./standalone');
|
||||
@@ -4,15 +4,14 @@ import { defineConfig } from 'vite';
|
||||
|
||||
import { honoServerDedupe, honoServerPlugins } from './viteNodeServer.config';
|
||||
|
||||
const serverRoot = fileURLToPath(new URL('../apps/server', import.meta.url));
|
||||
const entry = (file: string) =>
|
||||
fileURLToPath(new URL(`../apps/server/src/hono/${file}`, import.meta.url));
|
||||
const serverRoot = fileURLToPath(new URL('.', import.meta.url));
|
||||
const entry = (file: string) => fileURLToPath(new URL(`./src/hono/${file}`, import.meta.url));
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
minify: false,
|
||||
outDir: fileURLToPath(new URL('../apps/server/dist', import.meta.url)),
|
||||
outDir: fileURLToPath(new URL('./dist', import.meta.url)),
|
||||
rollupOptions: {
|
||||
input: {
|
||||
index: entry('index.ts'),
|
||||
+1
-1
@@ -72,7 +72,7 @@
|
||||
"dev:docker": "docker compose -f docker-compose/dev/docker-compose.yml up -d --wait postgresql redis rustfs searxng",
|
||||
"dev:docker:down": "docker compose -f docker-compose/dev/docker-compose.yml down",
|
||||
"dev:docker:reset": "docker compose -f docker-compose/dev/docker-compose.yml down -v && rm -rf docker-compose/dev/data && npm run dev:docker && pnpm db:migrate",
|
||||
"dev:hono:server": "npx vite-node --watch --config scripts/viteNodeServer.config.ts apps/server/src/hono/standalone.ts",
|
||||
"dev:hono:server": "pnpm --filter @lobechat/server dev",
|
||||
"dev:hono-lite": "tsx scripts/devHonoLite.mts",
|
||||
"dev:login": "cross-env LOBE_DEV_TOPOLOGY=hono-lite tsx scripts/devLocalLogin.mts",
|
||||
"dev:next": "next dev -p 3010",
|
||||
|
||||
Reference in New Issue
Block a user