feat(site): 完善官网主体信息与部署配置

This commit is contained in:
Zhou Weidong committed 2026-11-17 10:06:41 +08:00
1 parent dfa9f311e0
commit 0dc1b3a68e
14 files changed
+147 -20

No files matched your search

+25 -2
View File
@@ -1,5 +1,28 @@
// Author: fruit.com.cn
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
export default defineConfig({ plugins: [react()], server: { proxy: { '/app': { target: 'http://127.0.0.1:8081', changeOrigin: true }, '/files': { target: 'http://127.0.0.1:8081', changeOrigin: true } } } });
/** 把 public 里的 __SITE_URL__ 占位符替换成 .env 的 VITE_SITE_URL,域名只改一处。 */
function siteUrlPlugin() {
return {
name: 'site-url-replace',
apply: 'build',
closeBundle() {
const env = loadEnv('production', process.cwd(), '');
const url = (env.VITE_SITE_URL || '').replace(/\/$/, '');
if (!url) return;
for (const file of ['sitemap.xml', 'robots.txt']) {
const path = resolve('dist', file);
try {
writeFileSync(path, readFileSync(path, 'utf8').replaceAll('__SITE_URL__', url));
} catch {
// 文件不存在时忽略
}
}
},
};
}
export default defineConfig({ plugins: [react(), siteUrlPlugin()], server: { proxy: { '/app': { target: 'http://127.0.0.1:8081', changeOrigin: true }, '/files': { target: 'http://127.0.0.1:8081', changeOrigin: true } } } });