Skip to content

Commit

Permalink
feat: Add build output directory config
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleeWa committed Oct 14, 2024
1 parent 21256c2 commit 66fc15d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VITE_APP_PUBLIC_PATH=/
VITE_APP_PREVIEW=true
VITE_APP_API_BASE_URL=/api
VITE_APP_API_BASE_URL=/api
VITE_APP_OUT_DIR=dist
10 changes: 8 additions & 2 deletions build/vite/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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({
Expand All @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {

return {
base: env.VITE_APP_PUBLIC_PATH,
plugins: createVitePlugins(),
plugins: createVitePlugins(mode),

server: {
host: true,
Expand Down Expand Up @@ -58,6 +58,7 @@ export default ({ mode }: ConfigEnv): UserConfig => {
build: {
cssCodeSplit: false,
chunkSizeWarningLimit: 2048,
outDir: env.VITE_APP_OUT_DIR || 'dist',
},

optimizeDeps: { include, exclude },
Expand Down

0 comments on commit 66fc15d

Please sign in to comment.