From bedb8befa79410c6cf3ea9fc953af444de53155c Mon Sep 17 00:00:00 2001 From: lutinglt Date: Sat, 28 Jun 2025 11:58:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=80=E5=8F=91=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 4 ++++ .gitignore | 1 + package.json | 1 + src/core/vite.ts | 21 +++++++++++++++++++++ vite.config.ts | 5 ++++- 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..be2e09e --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +DEV_THEME=dark +SSH_SERVER=localhost +SSH_USER=root +GITEA_THEME_PATH=/data/gitea/public/assets/css/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 91a3983..6fbad4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist node_modules package-lock.json +.env \ No newline at end of file diff --git a/package.json b/package.json index 5797c5d..57c59c1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/core/vite.ts b/src/core/vite.ts index 893285a..4323d0d 100644 --- a/src/core/vite.ts +++ b/src/core/vite.ts @@ -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"); + } + }, }; } diff --git a/vite.config.ts b/vite.config.ts index 299a038..d2c70f7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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"; // 颜色主题目录