Initial commit

This commit is contained in:
yuantao
2025-09-29 14:05:25 +08:00
commit 6f0bb2f949
579 changed files with 99061 additions and 0 deletions

47
vite.config.js Normal file
View File

@@ -0,0 +1,47 @@
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import { resolve } from 'path'
import { readFileSync, writeFileSync } from 'fs'
import dotenv from 'dotenv'
// 自定义插件:替换 manifest.json 中的 appid
function replaceManifestAppid() {
return {
name: 'replace-manifest-appid',
buildStart() {
// 获取环境变量,明确指定路径为项目根目录
dotenv.config({ path: resolve(__dirname, '.env') })
const appid = process.env.VITE_APPID
const uni_appId = process.env.VITE_UNI_APPID
if (appid && uni_appId) {
// 读取 manifest.json 文件
const manifestPath = resolve(__dirname, 'manifest.json')
let manifestContent = readFileSync(manifestPath, 'utf-8')
// 解析 JSON
const manifest = JSON.parse(manifestContent)
// 替换
manifest.appid = uni_appId
if (manifest['mp-weixin']) {
manifest['mp-weixin'].appid = appid
}
// 写回文件
writeFileSync(manifestPath, JSON.stringify(manifest, null, 4))
console.log(`Manifest appid 已更新为: ${appid}`)
} else {
console.warn('未找到 VITE_APPID 和 VITE_UNI_APPID 环境变量,使用默认值')
}
},
}
}
export default defineConfig({
plugins: [replaceManifestAppid(), uni()],
server: {
port: 3000,
},
})