diff --git a/.env b/.env index 6d32d0d..ec6e2c6 100644 --- a/.env +++ b/.env @@ -1,3 +1,4 @@ VITE_APP_PUBLIC_PATH=/ VITE_APP_PREVIEW=true -VITE_APP_API_BASE_URL=/api \ No newline at end of file +VITE_APP_API_BASE_URL=/api +VITE_APP_OUT_DIR=dist diff --git a/build/vite/index.ts b/build/vite/index.ts index a05645b..f19adf6 100644 --- a/build/vite/index.ts +++ b/build/vite/index.ts @@ -1,5 +1,6 @@ import { dirname, resolve } from 'node:path' import { fileURLToPath } from 'node:url' +import process from 'node:process' import { unheadVueComposablesImports } from '@unhead/vue' import legacy from '@vitejs/plugin-legacy' import vue from '@vitejs/plugin-vue' @@ -15,8 +16,11 @@ import Sitemap from 'vite-plugin-sitemap' import VueDevTools from 'vite-plugin-vue-devtools' import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite' import { createViteVConsole } from './vconsole' +import { loadEnv } from 'vite' + +export function createVitePlugins(mode: string) { + const env = loadEnv(mode, process.cwd()) -export function createVitePlugins() { return [ // https://github.com/posva/unplugin-vue-router VueRouter({ @@ -28,7 +32,9 @@ export function createVitePlugins() { vue(), // https://github.com/jbaubree/vite-plugin-sitemap - Sitemap(), + Sitemap({ + outDir: env.VITE_APP_OUT_DIR || 'dist', + }), // https://github.com/pengzhanbo/vite-plugin-mock-dev-server mockDevServerPlugin(), diff --git a/vite.config.ts b/vite.config.ts index 5c3d995..dbd465d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -13,7 +13,7 @@ export default ({ mode }: ConfigEnv): UserConfig => { return { base: env.VITE_APP_PUBLIC_PATH, - plugins: createVitePlugins(), + plugins: createVitePlugins(mode), server: { host: true, @@ -58,6 +58,7 @@ export default ({ mode }: ConfigEnv): UserConfig => { build: { cssCodeSplit: false, chunkSizeWarningLimit: 2048, + outDir: env.VITE_APP_OUT_DIR || 'dist', }, optimizeDeps: { include, exclude },