Files

83 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2024-09-13 16:34:15 +08:00
import { defineConfig } from 'vite'
import * as path from 'path'
import * as dotenv from 'dotenv'
import * as fs from 'fs'
import vue from '@vitejs/plugin-vue'
const NODE_ENV = process.env.NODE_ENV || 'development'
const envFile = `.env.${NODE_ENV}`
const envConfig = dotenv.parse(fs.readFileSync(envFile))
for (const k in envConfig) {
process.env[k] = envConfig[k]
}
let alias = {
'@': path.resolve(__dirname, './src'),
'vue$': 'vue/dist/vue.runtime.esm-bundler.js',
}
const conf = {
2026-05-18 11:06:08 +02:00
base: './', // index.html File Location
root: './', //The resource path imported by JavaScript (src)
2024-09-13 16:34:15 +08:00
server: {
open: true,
port: process.env.VITE_DEV_PORT,
proxy: {
[process.env.VITE_SERVER_API]: {
target: process.env.VITE_SERVER_PATH,
2026-05-18 11:06:08 +02:00
// rewrite: path => path.replace(/^\/api/, '/api'), //In order to simulate
2024-09-13 16:34:15 +08:00
changeOrigin: true,
},
},
},
build: {
2024-10-09 15:52:17 +08:00
target: 'es2020',
2026-05-18 11:06:08 +02:00
minify: 'esbuild', // Whether to perform compression. Type: `boolean | 'terser' | 'esbuild'`. Defaults to `esbuild`.
manifest: false, // Generate manifest.json?
sourcemap: false, // Whether to generate sourceMap.json
2024-09-13 16:34:15 +08:00
emptyOutDir: true,
2026-05-18 11:06:08 +02:00
outDir: 'dist', // Output Directory
2024-09-13 16:34:15 +08:00
rollupOptions: {
output: {
manualChunks (id) {
if (id.includes('node_modules')) {
const arr = id.toString().split('node_modules/')[1].split('/')
switch (arr[0]) {
case '@popperjs':
case '@vue':
case 'axios':
case 'element-plus':
case '@element-plus':
return '_' + arr[0]
default :
return '__vendor'
}
}else if(id.includes('Gwen-admin/src')){
2026-05-18 11:06:08 +02:00
// Bundle everything under `src` together; otherwise, you'll end up with a multitude of small files.
2024-09-13 16:34:15 +08:00
return 'gwen'
}
},
chunkFileNames: 'static/chunk/[name]-[hash].js',
entryFileNames: 'static/entry/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
},
},
},
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
},
},
},
resolve: {
alias,
},
plugins: [
vue(),
],
}
// https://vitejs.dev/config/
export default defineConfig(conf)