Browse Source
- Refactored build scripts in package.json for better clarity and functionality. - Added new environment variables and paths for production and development setups. - Improved chat component with dynamic message handling and error management. - Updated dependencies in package.json for enhanced performance and compatibility.mono
18 changed files with 236 additions and 93 deletions
Binary file not shown.
@ -1,23 +1,18 @@ |
|||||
import path from "node:path" |
import path from "node:path" |
||||
import fs from "node:fs/promises" |
import fs from "node:fs/promises" |
||||
|
|
||||
const isProduction = process.env.NODE_ENV === 'production' |
export const isProduction = process.env.NODE_ENV === 'production' |
||||
|
|
||||
export function getPathByRoot(...argus: string[]) { |
export function getPathByRoot(...argus: string[]) { |
||||
return path.resolve(import.meta.dir, '../../..', ...argus) |
return path.resolve(import.meta.dir, '../../..', ...argus) |
||||
} |
} |
||||
|
|
||||
const templateHtml = isProduction |
// 生产环境路径配置
|
||||
? await fs.readFile(getPathByRoot('packages', 'client/index.html'), 'utf-8') |
export const TemplateHtml = isProduction ? await fs.readFile('./client/index.html', 'utf-8') : "" |
||||
: '' |
export const serverPublic = path.resolve("./public") |
||||
|
export const serverModules = path.resolve("./modules") |
||||
export function getDevPathFromClient(...argus: string[]) { |
export const jobsDir = path.resolve("./jobs/jobs") |
||||
return getPathByRoot('packages', 'client', ...argus) |
export const clientRoot = path.resolve("./client") |
||||
} |
export const ssrManifest = path.resolve('./client/.vite/ssr-manifest.json') |
||||
export function getDevPathFromServer(...argus: string[]) { |
export const entryServer = path.resolve('./server/entry-server.js') |
||||
return getPathByRoot('packages', 'server', ...argus) |
export const logDir = path.resolve('./logs') |
||||
} |
|
||||
|
|
||||
export function getProdPath(...argus: string[]) { |
|
||||
return getPathByRoot('dist', ...argus) |
|
||||
} |
|
||||
|
|||||
@ -0,0 +1,65 @@ |
|||||
|
#!/usr/bin/env node
|
||||
|
import { readFileSync, writeFileSync } from 'fs'; |
||||
|
import { join, dirname } from 'path'; |
||||
|
import { fileURLToPath } from 'url'; |
||||
|
|
||||
|
// 获取当前文件目录
|
||||
|
const __filename = fileURLToPath(import.meta.url); |
||||
|
const __dirname = dirname(__filename); |
||||
|
const projectRoot = join(__dirname, '..'); |
||||
|
|
||||
|
console.log('🚀 开始构建项目...'); |
||||
|
|
||||
|
try { |
||||
|
// 1. 读取package.json文件
|
||||
|
console.log('📋 读取package.json文件...'); |
||||
|
const rootPackageJson = JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8')); |
||||
|
const serverPackageJson = JSON.parse(readFileSync(join(projectRoot, 'packages/server/package.json'), 'utf8')); |
||||
|
|
||||
|
// 2. 合并依赖
|
||||
|
console.log('🔗 合并依赖...'); |
||||
|
const mergedDependencies = { |
||||
|
...rootPackageJson.dependencies, |
||||
|
...serverPackageJson.dependencies |
||||
|
}; |
||||
|
|
||||
|
// 3. 创建生产环境的package.json
|
||||
|
const productionPackageJson = { |
||||
|
name: rootPackageJson.name, |
||||
|
type: 'module', |
||||
|
version: rootPackageJson.version || '1.0.0', |
||||
|
description: 'Koa SSR 生产环境应用', |
||||
|
main: 'booststap.js', |
||||
|
scripts: { |
||||
|
start: 'bun run booststap.js' |
||||
|
}, |
||||
|
dependencies: mergedDependencies, |
||||
|
engines: { |
||||
|
bun: '>=1.0.0' |
||||
|
}, |
||||
|
keywords: ['koa', 'ssr', 'vue', 'bun'], |
||||
|
author: '', |
||||
|
license: 'MIT' |
||||
|
}; |
||||
|
|
||||
|
// 4. 写入新的package.json到dist目录
|
||||
|
console.log('💾 生成生产环境package.json...'); |
||||
|
const distPackageJsonPath = join(projectRoot, 'dist', 'package.json'); |
||||
|
writeFileSync(distPackageJsonPath, JSON.stringify(productionPackageJson, null, 2)); |
||||
|
console.log('✅ package.json 已生成到 dist/package.json'); |
||||
|
|
||||
|
// 5. 显示合并后的依赖信息
|
||||
|
console.log('\n📊 依赖合并结果:'); |
||||
|
console.log(`- 根目录依赖: ${Object.keys(rootPackageJson.dependencies || {}).length} 个`); |
||||
|
console.log(`- Server依赖: ${Object.keys(serverPackageJson.dependencies || {}).length} 个`); |
||||
|
console.log(`- 合并后总依赖: ${Object.keys(mergedDependencies).length} 个`); |
||||
|
|
||||
|
console.log('\n🎉 构建脚本执行完成!'); |
||||
|
console.log('📁 生产环境文件已生成到 dist/ 目录'); |
||||
|
console.log('💡 可以使用以下命令启动生产环境:'); |
||||
|
console.log(' cd dist && bun install && bun run start'); |
||||
|
|
||||
|
} catch (error) { |
||||
|
console.error('❌ 构建过程中发生错误:', error.message); |
||||
|
process.exit(1); |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
import { defineConfig } from "tsup"; |
||||
|
import pkg from "./package.json"; |
||||
|
import spkg from "./packages/server/package.json"; |
||||
|
import fg from "fast-glob" |
||||
|
|
||||
|
const jobsEntries = await fg(["packages/server/src/jobs/**/*.ts"], { }); |
||||
|
const modulesEntries = await fg(["packages/server/src/modules/**/*.ts"], { }); |
||||
|
|
||||
|
|
||||
|
export default defineConfig({ |
||||
|
entry: ["packages/server/src/booststap.ts", ...jobsEntries, ...modulesEntries], |
||||
|
format: "esm", |
||||
|
sourcemap: false, |
||||
|
clean: false, |
||||
|
cjsInterop: true, |
||||
|
external: [ |
||||
|
...Object.keys(pkg.dependencies), |
||||
|
...Object.keys(spkg.dependencies), |
||||
|
] |
||||
|
}); |
||||
@ -0,0 +1,18 @@ |
|||||
|
import { defineConfig } from 'tsup' |
||||
|
import pkg from "./package.json"; |
||||
|
import spkg from "./packages/server/package.json"; |
||||
|
import fg from "fast-glob" |
||||
|
|
||||
|
const entries = await fg(["packages/server/src/jobs/**/*.ts"], { }); |
||||
|
|
||||
|
export default defineConfig({ |
||||
|
entry: entries, |
||||
|
format: 'esm', |
||||
|
sourcemap: false, |
||||
|
clean: false, |
||||
|
outDir: "dist/jobs", |
||||
|
external: [ |
||||
|
...Object.keys(pkg.dependencies), |
||||
|
...Object.keys(spkg.dependencies), |
||||
|
] |
||||
|
}) |
||||
@ -0,0 +1,18 @@ |
|||||
|
import { defineConfig } from 'tsup' |
||||
|
import pkg from "./package.json"; |
||||
|
import spkg from "./packages/server/package.json"; |
||||
|
import fg from "fast-glob" |
||||
|
|
||||
|
const entries = await fg(["packages/server/src/modules/**/*.ts"], { }); |
||||
|
|
||||
|
export default defineConfig({ |
||||
|
entry: entries, |
||||
|
format: 'esm', |
||||
|
sourcemap: false, |
||||
|
clean: false, |
||||
|
outDir: "dist/modules", |
||||
|
external: [ |
||||
|
...Object.keys(pkg.dependencies), |
||||
|
...Object.keys(spkg.dependencies), |
||||
|
] |
||||
|
}) |
||||
Loading…
Reference in new issue