Browse Source

打包配置

master
maziyang 3 months ago
parent
commit
817a10b6c4
  1. 52
      vite.config.js

52
vite.config.js

@ -1,18 +1,46 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
vueDevTools(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
export default defineConfig(({ mode, command }) => {
// 正确加载环境变量 - 只加载 VITE_ 前缀的变量:cite[9]
const env = loadEnv(mode, process.cwd(), 'VITE_')
const outDirMap = {
development: 'dist-test',
production: 'dist-prod'
}
return {
// 确保基础路径正确
base: './',
plugins: [
vue(),
vueDevTools(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
build: {
outDir: outDirMap[mode] || 'dist',
rollupOptions: {
input: {
main: './index.html',
},
output: {
entryFileNames: '[name].js', // 入口文件命名
chunkFileNames: '[name].js', // 代码分割块命名
assetFileNames: '[name].[ext]' // 静态资源命名
}
}
},
server: {
port: 5173,
open: true
},
},
})
}
})
Loading…
Cancel
Save