From 66842e9d5887de0eb0dde45aa6d32ed987a5feee Mon Sep 17 00:00:00 2001 From: zhongyingmin Date: Sun, 14 Sep 2025 13:15:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20Vite=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BB=A5=E6=94=AF=E6=8C=81=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=92=8C=E5=9F=BA=E7=A1=80=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 8 ++++++++ .env.production | 6 ++++++ vite.config.ts | 19 +++++++++++++------ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..77d97b2 --- /dev/null +++ b/.env.development @@ -0,0 +1,8 @@ +# 环境 +VITE_NODE_ENV=development + +# 线上环境平台打包路径 +VITE_BASE_PATH=/super-video-h5 + + + diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..99125ef --- /dev/null +++ b/.env.production @@ -0,0 +1,6 @@ +# 环境 +VITE_NODE_ENV=production + +# 线上环境平台打包路径 +VITE_BASE_PATH=/super-video-h5 + diff --git a/vite.config.ts b/vite.config.ts index 6ef2069..3893c8e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,13 +1,20 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' +// 当前工作目录路径 +const root: string = process.cwd() // https://vite.dev/config/ -export default defineConfig({ - plugins: [vue()], - resolve: { - alias: { - '@': resolve(__dirname, 'src') +export default defineConfig(({ mode }) => { + // 环境变量 + const env = loadEnv(mode, root, '') + return { + plugins: [vue()], + base: env.VITE_BASE_PATH || '/', + resolve: { + alias: { + '@': resolve(__dirname, 'src') + } } } })