summaryrefslogtreecommitdiff
path: root/vite.config.js
blob: 4790be85711c0be774016e5232065ba9bb8bc2ba (plain)
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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      //别名配置
      '@': path.resolve(__dirname, './src'),
      '~/': `${path.resolve(__dirname, 'src')}/`,
    },
  },
  //本地运行配置,以及反向代理配置
  server: {
    host: true,
    port: '8080', //端口
    open: true, //服务启动时自动在浏览器中打开应用
  },
  css: {
    // css预处理器
    preprocessorOptions: {
      scss: {
        // 引入 variables.scss 这样就可以在全局中使用 variables.scss中预定义的变量了
        // 给导入的路径最后加上 ;
        additionalData: `@use "@/styles/variables.scss" as *; `,
      },
    },
  },
  build: {
    outDir: 'dist', //指定输出文件
    assetsDir:"./static",  //指定生成静态文件目录
    rollupOptions: {
      output: {
        chunkFileNames: 'static/js/[name]-[hash].js',
        entryFileNames: 'static/js/[name]-[hash].js',
        assetFileNames: (chunkInfo) => {
          if(['.png', '.jpg', '.jpeg'].includes(path.extname(chunkInfo.name))) {
            return `static/[ext]/[name].[ext]`
          }
          return `static/[ext]/[name]-[hash].[ext]`
        },
      },
    },
  },
});