添加开发环境变量

This commit is contained in:
lutinglt
2025-06-28 11:58:36 +08:00
parent 5ae1f2f634
commit bedb8befa7
5 changed files with 31 additions and 1 deletions

4
.env.example Normal file
View File

@@ -0,0 +1,4 @@
DEV_THEME=dark
SSH_SERVER=localhost
SSH_USER=root
GITEA_THEME_PATH=/data/gitea/public/assets/css/

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
dist
node_modules
package-lock.json
.env

View File

@@ -26,6 +26,7 @@
"@vitejs/plugin-react-swc": "^3.10.2",
"@wyw-in-js/babel-preset": "^0.7.0",
"@wyw-in-js/vite": "^0.7.0",
"dotenv": "^17.0.0",
"eslint": "^9.29.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",

View File

@@ -1,3 +1,4 @@
import { execSync } from "node:child_process";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
@@ -46,6 +47,9 @@ export function themeInput(
input[fileName] = tmpInputTs;
}
}
if (mode === "dev") {
console.log("[themeInput] devTheme:", devTheme);
}
return input;
}
@@ -88,5 +92,22 @@ export function themePlugin(): Plugin {
}
}
},
closeBundle() {
const server = process.env.SSH_SERVER;
const user = process.env.SSH_USER || "root";
const path = process.env.GITEA_THEME_PATH;
if (server && path) {
const cmd = `scp dist/${prefix}*.css ${user}@${server}:${path}`;
console.log("[themePlugin] exec:", cmd);
try {
execSync(cmd, { stdio: "inherit" });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_) {
// continue regardless of error
}
} else {
console.log("[themePlugin] no SSH_SERVER or GITEA_THEME_PATH, skip upload");
}
},
};
}

View File

@@ -1,6 +1,7 @@
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
import react from "@vitejs/plugin-react";
import linaria from "@wyw-in-js/vite";
import * as dotenv from "dotenv";
import { Features } from "lightningcss";
import { createRequire } from "node:module";
import path from "node:path";
@@ -8,9 +9,11 @@ import * as sass from "sass-embedded";
import { defineConfig } from "vite";
import { themeInput, themePlugin } from "./src/core/vite";
dotenv.config({quiet: true});
const require = createRequire(import.meta.url);
const devTheme = "dark"; // 开发模式仅打包单个颜色主题
const devTheme = process.env.DEV_THEME || "dark"; // 开发模式下的主题, 仅打包该主题
const outDir = "dist"; // 输出目录
const themesDir = "themes"; // 颜色主题目录