| | |
| | | * Copyright 2025 OBKoro1, All Rights Reserved. |
| | | * 2025-09-28 09:31:16 |
| | | */ |
| | | export const createViteProxy = (env) => { |
| | | const { VITE_APP_PROXY, VITE_API_PREFIX, VITE_API_BASE_URL } = env |
| | | import configEnv from "../../src/config/env.js"; |
| | | |
| | | export const createViteProxy = (env,envName) => { |
| | | const { VITE_APP_PROXY, VITE_API_PREFIX } = env |
| | | // 不使用代理直接返回 |
| | | if (!JSON.parse(VITE_APP_PROXY)) return undefined |
| | | const proxy = { |
| | | [VITE_API_PREFIX]: { |
| | | target: VITE_API_BASE_URL, |
| | | target: configEnv[envName].VITE_API_BASE_URL, |
| | | changeOrigin: true, |
| | | rewrite: path => path.replace(new RegExp(`^${VITE_API_PREFIX}`), ''), |
| | | }, |
| | |
| | | import { AutoRegistryComponents } from './component' |
| | | import { MCPPlugin } from './mcp' |
| | | import { ConfigUnoCSSPlugin } from './unocss' |
| | | |
| | | export default function createVitePlugins (isBuild) { |
| | | const vitePlugins = [ |
| | | // UnoCSS配置 |
| | |
| | | VITE_APP_ENV=production |
| | | |
| | | # 删除console |
| | | VITE_DROP_CONSOLE=true |
| | | VITE_DROP_CONSOLE=false |
| | |
| | | } |
| | | |
| | | const test = { |
| | | VITE_APP_ENV:'development', |
| | | VITE_APP_ENV:'test', |
| | | VITE_APP_WEBVIEW_URL: 'https://wrj.shuixiongit.com/drone-app-web-view/#/webViewWrapper', |
| | | VITE_API_BASE_URL: 'https://wrj.shuixiongit.com/api', |
| | | } |
| | |
| | | import 'leaflet/dist/leaflet.css' |
| | | |
| | | import {getEnvObj} from "@/utils/index.js"; |
| | | console.log('process.env.ENV_NAME',) |
| | | console.log('当前环境变量',getEnvObj()) |
| | | export function createApp () { |
| | | const app = createSSRApp(App) |
| | |
| | | // 小程序更新检测 |
| | | import { useUserStore } from "@/store/index.js" |
| | | import configEnv from "@/config/env.js"; |
| | | import process from "node:process" |
| | | import process from "node:process"; |
| | | |
| | | export function mpUpdate () { |
| | | const updateManager = uni.getUpdateManager() |
| | |
| | | } |
| | | |
| | | export function getEnvObj() { |
| | | return configEnv?.[process?.env?.ENV_NAME] || {} |
| | | const envName = JSON.parse(__APP_ENV__.UNI_CUSTOM_DEFINE)?.ENV_NAME |
| | | return configEnv[envName] || {} |
| | | } |
| | | export function getWebViewUrl (targetUrl, otherParams) { |
| | | const userStore = useUserStore() |
| | | const url = getEnvObj().VITE_APP_WEBVIEW_URL |
| | | console.log(getEnvObj(),'getEnvObj()') |
| | | // 1. 处理用户参数 |
| | | const userParams = userStore?.userInfo ? JSON.stringify(userStore.userInfo) : '{}' |
| | | // 2. 构建查询参数字符串 |
| | |
| | | import { defineConfig, loadEnv } from "vite" |
| | | import { createViteProxy } from "./build/config/index" |
| | | import createVitePlugins from "./build/plugins/index" |
| | | import configEnv from "./src/config/env.js"; |
| | | |
| | | // https://vitejs.dev/config/ |
| | | export default defineConfig(({ command, mode }) => { |
| | |
| | | console.log("command, mode -> ", command, mode) |
| | | |
| | | const { UNI_PLATFORM,UNI_CUSTOM_DEFINE } = process.env |
| | | const ENV_NAME = UNI_CUSTOM_DEFINE && JSON.parse(UNI_CUSTOM_DEFINE)?.ENV_NAME |
| | | console.log("平台 -> ", UNI_PLATFORM) // 得到 mp-weixin, h5, app 等 |
| | | console.log("环境 -> ", UNI_CUSTOM_DEFINE && JSON.parse(UNI_CUSTOM_DEFINE)?.ENV_NAME) // 得到 development,test 等 |
| | | console.log("环境 -> ", ENV_NAME) // 得到 development,test 等 |
| | | |
| | | const env = loadEnv(mode, fileURLToPath(new URL("./env", import.meta.url))) |
| | | // console.log("环境变量 env -> ", env) |
| | | const isBuild = process.env.NODE_ENV === "production" |
| | | return { |
| | | define: { |
| | | __APP_ENV__: process.env, |
| | | }, |
| | | // 自定义env目录 |
| | | envDir: "./env", |
| | | resolve: { |
| | |
| | | hmr: true, |
| | | host: true, |
| | | open: true, |
| | | proxy: createViteProxy(env) |
| | | proxy: createViteProxy(env,ENV_NAME) |
| | | }, |
| | | // 设置scss的api类型为modern-compiler |
| | | css: { |