he wei
2025-04-25 53310b6f8b2274c3d68674648446451761edea21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueSetupExtend from 'vite-plugin-vue-setup-extend';
import { fileURLToPath, URL } from 'node:url';
import svgSprites from 'rollup-plugin-svg-sprites';
import Inspect from 'vite-plugin-inspect';
import path from 'node:path';
import json from '@rollup/plugin-json';
 
// https://vite.dev/config/
export default defineConfig((command, mode) => {
 
  const env = loadEnv(mode, process.cwd(), '');
  return {
    plugins: [
      vue(),
      Inspect(),
      VueSetupExtend(),
      json({
        // 支持按名导入
        namedExports: true,
        // 生成 compact 版本的 JSON
        compact: true 
      }),
      svgSprites({
        vueComponent: true,
        exclude: ['node_modules/**'],
        symbolId(filePath) {
          const filename = path.basename(filePath);
          return 'icon-' + filename.substring(0, filename.lastIndexOf('.'));
        }
      }),
    ],
    base: './',
    define: {
      'process.env': env
    },
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    },
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
    },
    server: {
      host: 'localhost',
      port: 5273
    }
  }
});