diff --git a/.env b/.env
new file mode 100644
index 0000000..07e7edc
--- /dev/null
+++ b/.env
@@ -0,0 +1 @@
+VITE_UMAMI_SCRIPT=
\ No newline at end of file
diff --git a/.env.production b/.env.production
new file mode 100644
index 0000000..7d56576
--- /dev/null
+++ b/.env.production
@@ -0,0 +1 @@
+VITE_UMAMI_SCRIPT=
\ No newline at end of file
diff --git a/vite.config.ts b/vite.config.ts
index efdfa40..ad1f09d 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -4,16 +4,11 @@ import preact from '@preact/preset-vite';
declare const process: {
env: {
GITHUB_PAGES?: string;
- NODE_ENV?: string;
};
};
-// 检查是否是 GitHub Pages 环境
-const isGitHubPages = process.env.GITHUB_PAGES === 'true';
-// 检查是否是生产环境
-const isProduction = process.env.NODE_ENV === 'production';
-
export default defineConfig({
+ plugins: [ preact() ],
server: {
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
@@ -31,29 +26,8 @@ export default defineConfig({
},
},
optimizeDeps: {
- include: ['pikafish'],
+ include: [ 'pikafish' ],
},
// 根据环境动态设置 base
- base: isGitHubPages ? '/xiangqi-analysis/' : '/',
- // 添加 HTML 替换逻辑
- define: {
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
- },
- plugins: [
- preact(),
- {
- name: 'html-transform',
- transformIndexHtml(html) {
- // 只在生产环境中注入统计脚本
- if (isProduction) {
- return html.replace(
- '%VITE_UMAMI_SCRIPT%',
- ''
- );
- }
- // 在开发环境中移除占位符
- return html.replace('%VITE_UMAMI_SCRIPT%', '');
- },
- },
- ],
-});
+ base: process.env.GITHUB_PAGES === 'true' ? '/xiangqi-analysis/' : '/',
+});
\ No newline at end of file