build: 打通 FastAPI 与 Vue 最小工程、依赖与数据库连接
后端入口、配置、Redis 与 Alembic 迁移就位;前端 Vite 工程可安装可构建。
This commit is contained in:
1 parent
ec5835ca77
commit
977783c126
167 files changed
+26082
No files matched your search
@@ -0,0 +1,76 @@
|
||||
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 development environment variables
|
||||
dotenv.config({ path: '.env.dev' })
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = dirname(__filename)
|
||||
|
||||
async function buildWebClientDev() {
|
||||
try {
|
||||
console.log('Building webclient with development configuration...')
|
||||
|
||||
// For development, we use the existing config.js which is already set for development
|
||||
// No need to copy files like in production build
|
||||
console.log('Using existing config.js for development build')
|
||||
|
||||
// Set NODE_ENV to development for the build
|
||||
process.env.NODE_ENV = 'development'
|
||||
|
||||
// Baked DEFAULT base URL only; getBaseUrl() still resolves
|
||||
// window.replypierBaseUrl / window.APP_CONFIG at runtime, so no rebuild is
|
||||
// needed when a deployment's env changes.
|
||||
const apiUrl = process.env.VITE_API_URL || 'http://localhost:8000/api/v1'
|
||||
console.log('Using API URL:', apiUrl)
|
||||
|
||||
const sourceFile = resolve(dirname(__dirname), 'src/webclient/replypier.js')
|
||||
|
||||
await build({
|
||||
entryPoints: [sourceFile],
|
||||
bundle: true,
|
||||
minify: false, // Don't minify for development
|
||||
outfile: resolve(dirname(__dirname), 'public/webclient/replypier.min.js'),
|
||||
format: 'iife',
|
||||
target: ['es2015'],
|
||||
loader: {
|
||||
'.svg': 'text',
|
||||
},
|
||||
define: {
|
||||
'process.env.NODE_ENV': '"development"',
|
||||
'__REPLYPIER_API_URL__': JSON.stringify(apiUrl),
|
||||
},
|
||||
sourcemap: true, // Add sourcemap for development
|
||||
})
|
||||
|
||||
// Copy output to dist/webclient directory
|
||||
const publicWebclientPath = resolve(dirname(__dirname), 'public/webclient/replypier.min.js')
|
||||
const publicSourcemapPath = resolve(dirname(__dirname), 'public/webclient/replypier.min.js.map')
|
||||
const distWebclientDir = resolve(dirname(__dirname), 'dist/webclient')
|
||||
const distWebclientPath = resolve(distWebclientDir, 'replypier.min.js')
|
||||
const distSourcemapPath = resolve(distWebclientDir, 'replypier.min.js.map')
|
||||
|
||||
// Ensure dist/webclient directory exists
|
||||
if (!fs.existsSync(distWebclientDir)) {
|
||||
fs.mkdirSync(distWebclientDir, { recursive: true })
|
||||
}
|
||||
|
||||
// Copy the built file and sourcemap to dist/webclient
|
||||
fs.copyFileSync(publicWebclientPath, distWebclientPath)
|
||||
if (fs.existsSync(publicSourcemapPath)) {
|
||||
fs.copyFileSync(publicSourcemapPath, distSourcemapPath)
|
||||
}
|
||||
console.log('Development web client copied to dist/webclient/')
|
||||
|
||||
console.log('Development web client built successfully!')
|
||||
} catch (error) {
|
||||
console.error('Development build failed:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
buildWebClientDev()
|
||||
Reference in new issue
Block a user