vite.config.ts 2.49 KB
Newer Older
zhangsan's avatar
zhangsan committed
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import { VarletUIResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import { resolve } from 'path'
import vitePluginBundleObfuscator from 'vite-plugin-bundle-obfuscator';

export default defineConfig({
  plugins: [
    vue(),
    // 添加 legacy 插件支持旧版浏览器
    legacy({
      targets: ['ie >= 11', 'chrome >= 49', 'ios >= 8'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      modernPolyfills: true
    }),
    AutoImport({
      imports: [
        'vue',
        'vue-router',
      ],
      resolvers: [VantResolver()],
      dts: 'src/auto-imports.d.ts'
    }),
    Components({
      resolvers: [
        VantResolver({
          importStyle: true
        }),
        VarletUIResolver({
          autoImport: true,
          importStyle: true,
          resolveStyles: true,
          version: '2.22.8'
        })
      ],
      dts: 'src/components.d.ts',
      dirs: ['src/components']
    }),
    // vitePluginBundleObfuscator({
    //   enable: true,
    //   log: true,
    //   autoExcludeNodeModules: true,
    //   threadPool: true,
    // })
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          @use "sass:math";
          @use "@/styles/variables" as *;
          @use "@/styles/mixins" as *;
        `,
        sassOptions: {
          outputStyle: 'compressed'
        }
      }
    },
    postcss: {
      plugins: [
        require('postcss-px-to-viewport')({
          viewportWidth: 375,
          unitPrecision: 5,
          viewportUnit: 'vw',
          fontViewportUnit: 'vw',
          selectorBlackList: ['.ignore'],
          minPixelValue: 1,
          mediaQuery: false,
          exclude: /node_modules/i,
          propList: ['*', '!border*', '!font-size*', '!line-height*']
        })
      ]
    }
  },
  build: {
    target: 'es2015',
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
  },
  server: {
    port: 8080,
    open: true,
    proxy: {
      '/jeecg-boot': {
        // target: 'http://27.124.5.32:18080',
        target: 'https://www.sswgh.com',
        changeOrigin: true
      }
    }
  }
})