| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { defineConfig, loadEnv } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import path from 'path'
- // 引入@vitejs/plugin-legacy
- import legacy from '@vitejs/plugin-legacy'
- // https://vite.dev/config/
- export default defineConfig(({ mode }) => {
- // 加载对应模式的环境变量
- const env = loadEnv(mode, process.cwd())
- return {
- plugins: [
- legacy({
- targets: ['defaults', 'not IE 11']
- }),
- vue(),
- ],
- resolve: {
- // 路径别名配置
- alias: {
- '@': path.resolve(__dirname, './src')
- }
- },
- base: './',
- server: {
- host: '0.0.0.0',
- proxy: {
- '/admin-api': {
- // 使用加载的环境变量
- target: env.VITE_BASE_URL,
- changeOrigin: true
- }
- }
- },
- build: {
- outDir: 'aiWeb',
- rollupOptions: {
- output: {
- entryFileNames: `assets/[name]-[hash].js`,
- chunkFileNames: `assets/[name]-[hash].js`,
- // 保留原始目录结构
- assetFileNames: ({ name }) => {
- const extType = name.split('.').pop();
- if (/png|jpe?g|gif|svg|webp/i.test(extType)) {
- return `assets/images/[name].[ext]`;
- }
- if (/woff2?|ttf|otf|eot/i.test(extType)) {
- return `assets/typeface/[name].[ext]`;
- }
- if (/mp4/i.test(extType)) {
- return `assets/02video/[name].[ext]`;
- }
- return `assets/[name].[ext]`;
- }
- }
- }
- }
- }
- })
|