Skip to content

Commit 66fc15d

Browse files
committed
feat: Add build output directory config
1 parent 21256c2 commit 66fc15d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
VITE_APP_PUBLIC_PATH=/
22
VITE_APP_PREVIEW=true
3-
VITE_APP_API_BASE_URL=/api
3+
VITE_APP_API_BASE_URL=/api
4+
VITE_APP_OUT_DIR=dist

build/vite/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { dirname, resolve } from 'node:path'
22
import { fileURLToPath } from 'node:url'
3+
import process from 'node:process'
34
import { unheadVueComposablesImports } from '@unhead/vue'
45
import legacy from '@vitejs/plugin-legacy'
56
import vue from '@vitejs/plugin-vue'
@@ -15,8 +16,11 @@ import Sitemap from 'vite-plugin-sitemap'
1516
import VueDevTools from 'vite-plugin-vue-devtools'
1617
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
1718
import { createViteVConsole } from './vconsole'
19+
import { loadEnv } from 'vite'
20+
21+
export function createVitePlugins(mode: string) {
22+
const env = loadEnv(mode, process.cwd())
1823

19-
export function createVitePlugins() {
2024
return [
2125
// https://github.com/posva/unplugin-vue-router
2226
VueRouter({
@@ -28,7 +32,9 @@ export function createVitePlugins() {
2832
vue(),
2933

3034
// https://github.com/jbaubree/vite-plugin-sitemap
31-
Sitemap(),
35+
Sitemap({
36+
outDir: env.VITE_APP_OUT_DIR || 'dist',
37+
}),
3238

3339
// https://github.com/pengzhanbo/vite-plugin-mock-dev-server
3440
mockDevServerPlugin(),

vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {
1313

1414
return {
1515
base: env.VITE_APP_PUBLIC_PATH,
16-
plugins: createVitePlugins(),
16+
plugins: createVitePlugins(mode),
1717

1818
server: {
1919
host: true,
@@ -58,6 +58,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {
5858
build: {
5959
cssCodeSplit: false,
6060
chunkSizeWarningLimit: 2048,
61+
outDir: env.VITE_APP_OUT_DIR || 'dist',
6162
},
6263

6364
optimizeDeps: { include, exclude },

0 commit comments

Comments
 (0)