feat: 添加环境配置文件,更新.gitignore以排除dist-test目录,新增构建和预览测试脚本

This commit is contained in:
2026-01-15 00:57:35 +07:00
parent b09e92488b
commit 87782ad55d
4 changed files with 88 additions and 80 deletions

3
.env.test Normal file
View File

@@ -0,0 +1,3 @@
VITE_API_URL=http://192.168.1.7:9527
VITE_TRADINGVIEW_LIBRARY_URL=https://dev.riwsan1.com
# VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com

1
.gitignore vendored
View File

@@ -26,6 +26,7 @@ npm-debug.log*
!/.vscode/extensions.json !/.vscode/extensions.json
/coverage /coverage
/dist /dist
/dist-test
/dev-dist /dev-dist
/node_modules /node_modules
/platforms /platforms

View File

@@ -14,6 +14,8 @@
"deploy:cloudflare": "wrangler pages deploy dist --project-name=riwa --branch=main", "deploy:cloudflare": "wrangler pages deploy dist --project-name=riwa --branch=main",
"test:e2e": "cypress run", "test:e2e": "cypress run",
"test:unit": "vitest", "test:unit": "vitest",
"test:build": "vite build -m test --outDir dist-test",
"test:preview": "vite preview --port 6173 -m test --outDir dist-test",
"lint": "eslint", "lint": "eslint",
"lint:fix": "eslint --fix" "lint:fix": "eslint --fix"
}, },

View File

@@ -15,91 +15,93 @@ import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa"; import { VitePWA } from "vite-plugin-pwa";
import { generateVersion } from "./scripts/build"; import { generateVersion } from "./scripts/build";
dotenv.config({ path: `.env.${process.env.NODE_ENV}` });
const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8")); const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
const appVersion = packageJson.version; const appVersion = packageJson.version;
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig(({ mode }) => {
plugins: [ dotenv.config({ path: `.env.${mode}` });
vue(),
jsx(), return {
legacy(), plugins: [
icons({ vue(),
autoInstall: true, jsx(),
}), legacy(),
tailwindcss(), icons({
autoImport({ autoInstall: true,
dirs: ["src/composables", "src/utils", "src/store"], }),
imports: ["vue", "vue-router", "@vueuse/core", "vue-i18n", "pinia"], tailwindcss(),
resolvers: [IonicResolver()], autoImport({
vueTemplate: true, dirs: ["src/composables", "src/utils", "src/store"],
}), imports: ["vue", "vue-router", "@vueuse/core", "vue-i18n", "pinia"],
components({ resolvers: [IonicResolver()],
directoryAsNamespace: true, vueTemplate: true,
resolvers: [IonicResolver(), iconsResolver({ prefix: "i" })], }),
}), components({
VitePWA({ directoryAsNamespace: true,
registerType: "autoUpdate", resolvers: [IonicResolver(), iconsResolver({ prefix: "i" })],
injectRegister: "auto", }),
includeAssets: ["favicon.svg"], VitePWA({
devOptions: { registerType: "autoUpdate",
enabled: true, injectRegister: "auto",
type: "module", includeAssets: ["favicon.svg"],
}, devOptions: {
manifest: { enabled: true,
name: "Riwsan 瑞讯", type: "module",
short_name: "Riwsan 瑞讯", },
description: "Riwsan - 下一代数字资产交易平台", manifest: {
theme_color: "#ffffff", name: "Riwsan 瑞讯",
background_color: "#ffffff", short_name: "Riwsan 瑞讯",
display: "standalone", description: "Riwsan - 下一代数字资产交易平台",
orientation: "portrait", theme_color: "#ffffff",
scope: "/", background_color: "#ffffff",
start_url: "/", display: "standalone",
id: "/", orientation: "portrait",
prefer_related_applications: false, scope: "/",
icons: [ start_url: "/",
{ id: "/",
src: "/favicon.svg", prefer_related_applications: false,
sizes: "any", icons: [
type: "image/svg+xml", {
purpose: "any maskable", src: "/favicon.svg",
}, sizes: "any",
], type: "image/svg+xml",
}, purpose: "any maskable",
workbox: { },
globPatterns: ["**/*.{js,css,html,ico,png,svg,woff2}"], ],
navigateFallback: "/index.html", },
navigateFallbackDenylist: [/^\/api/], workbox: {
cleanupOutdatedCaches: true, globPatterns: ["**/*.{js,css,html,ico,png,svg,woff2}"],
clientsClaim: true, navigateFallback: "/index.html",
skipWaiting: true, navigateFallbackDenylist: [/^\/api/],
maximumFileSizeToCacheInBytes: 100 * 1024 * 1024, // 100 MB cleanupOutdatedCaches: true,
}, clientsClaim: true,
}), skipWaiting: true,
// basicSsl(), maximumFileSizeToCacheInBytes: 100 * 1024 * 1024, // 100 MB
generateVersion({ },
version: appVersion, }),
}), // basicSsl(),
], generateVersion({
define: { version: appVersion,
__APP_VERSION__: JSON.stringify(appVersion), }),
}, ],
resolve: { define: {
alias: { __APP_VERSION__: JSON.stringify(appVersion),
"@": path.resolve(__dirname, "./src"),
}, },
}, resolve: {
server: { alias: {
host: true, "@": path.resolve(__dirname, "./src"),
proxy: {
"/api": {
target: process.env.VITE_API_URL,
changeOrigin: true,
ws: true,
}, },
}, },
}, server: {
host: true,
proxy: {
"/api": {
target: process.env.VITE_API_URL,
changeOrigin: true,
ws: true,
},
},
},
};
}); });