build: 打通 FastAPI 与 Vue 最小工程、依赖与数据库连接
后端入口、配置、Redis 与 Alembic 迁移就位;前端 Vite 工程可安装可构建。
This commit is contained in:
1 parent
fb0ddca4de
commit
2aee6286d6
167 files changed
+26082
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { build } from 'esbuild'
|
||||
import { resolve, dirname } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import * as dotenv from 'dotenv'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
// Load production environment variables
|
||||
dotenv.config({ path: '.env.prod' })
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
async function buildWebClientProd() {
|
||||
try {
|
||||
console.log('Building webclient with production configuration...')
|
||||
|
||||
// Config is now generated by the prebuild step (generate-prod-env.ts)
|
||||
// No need to copy config files here
|
||||
|
||||
// Set NODE_ENV to production for the build
|
||||
process.env.NODE_ENV = 'production'
|
||||
|
||||
// Baked DEFAULT base URL. This only sets the fallback; getBaseUrl() still
|
||||
// resolves window.chattermateBaseUrl / window.APP_CONFIG at runtime, so an
|
||||
// env change on a deployment needs no rebuild of this artifact.
|
||||
const apiUrl = process.env.VITE_API_URL || 'https://api.chattermate.chat/api/v1'
|
||||
console.log('Using API URL:', apiUrl)
|
||||
|
||||
const sourceFile = resolve(dirname(__dirname), 'src/webclient/chattermate.js')
|
||||
|
||||
await build({
|
||||
entryPoints: [sourceFile],
|
||||
bundle: true,
|
||||
minify: true,
|
||||
outfile: resolve(dirname(__dirname), 'public/webclient/chattermate.min.js'),
|
||||
format: 'iife',
|
||||
target: ['es2015'],
|
||||
loader: {
|
||||
'.svg': 'text',
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': '"production"',
|
||||
'__CHATTERMATE_API_URL__': JSON.stringify(apiUrl),
|
||||
},
|
||||
})
|
||||
|
||||
// Copy output to dist/webclient directory
|
||||
const publicWebclientPath = resolve(dirname(__dirname), 'public/webclient/chattermate.min.js')
|
||||
const distWebclientDir = resolve(dirname(__dirname), 'dist/webclient')
|
||||
const distWebclientPath = resolve(distWebclientDir, 'chattermate.min.js')
|
||||
|
||||
// Ensure dist/webclient directory exists
|
||||
if (!fs.existsSync(distWebclientDir)) {
|
||||
fs.mkdirSync(distWebclientDir, { recursive: true })
|
||||
}
|
||||
|
||||
// Copy the built file to dist/webclient
|
||||
fs.copyFileSync(publicWebclientPath, distWebclientPath)
|
||||
console.log('Production web client copied to dist/webclient/')
|
||||
|
||||
console.log('Production web client built successfully!')
|
||||
} catch (error) {
|
||||
console.error('Production build failed:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
buildWebClientProd()
|
||||
Reference in new issue
Block a user