Files
replypier/frontend/scripts/build-webclient-prod.ts
T
WangShen007 54b949b392 chore(brand): rename the product to ReplyPier
The upstream project name is gone from code, assets, docs and build
output: brand strings, domains (replypier.site and its app/api/docs/help
subdomains), env prefixes, image and network names, the widget's public
JS API (window.ReplyPier, replypierId/BaseUrl/Config/Token), CSS tokens
(--rp-*), file and directory names, and the WordPress plugin package.

- widget loader is now webclient/replypier.min.js; both bundles rebuilt
  from source (backend/assets/widget.{js,css}, frontend/public/webclient)
- NOTICE, llms.txt, CONTRIBUTING, HELP_CENTER_INFRA and config.dev.js
  rewritten rather than string-swapped; the demo config no longer ships
  the previous vendor's Firebase/Razorpay/Google keys
- new migration replypier_ai_model_001 adds REPLYPIER to the managed
  AIModelType and rewrites pre-rename rows
- local compose project, database, role and volume renamed; LOCAL_DEPLOY
  documents carrying the old local data over
2026-10-26 00:51:03 +08:00

70 lines
2.3 KiB
TypeScript

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.replypierBaseUrl / 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.replypier.site/api/v1'
console.log('Using API URL:', apiUrl)
const sourceFile = resolve(dirname(__dirname), 'src/webclient/replypier.js')
await build({
entryPoints: [sourceFile],
bundle: true,
minify: true,
outfile: resolve(dirname(__dirname), 'public/webclient/replypier.min.js'),
format: 'iife',
target: ['es2015'],
loader: {
'.svg': 'text',
},
define: {
'process.env.NODE_ENV': '"production"',
'__REPLYPIER_API_URL__': JSON.stringify(apiUrl),
},
})
// Copy output to dist/webclient directory
const publicWebclientPath = resolve(dirname(__dirname), 'public/webclient/replypier.min.js')
const distWebclientDir = resolve(dirname(__dirname), 'dist/webclient')
const distWebclientPath = resolve(distWebclientDir, 'replypier.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()