vite.config.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { resolve } from 'path';
  2. import { defineConfig } from 'vite';
  3. import vue from '@vitejs/plugin-vue';
  4. import vueJsx from '@vitejs/plugin-vue-jsx';
  5. import { vitePluginCommonjs } from 'vite-plugin-commonjs';
  6. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
  7. import eslint from 'vite-plugin-eslint';
  8. import VueSetupExtend from 'vite-plugin-vue-setup-extend';
  9. // eslint-disable-next-line import/no-unresolved
  10. import AutoImport from 'unplugin-auto-import/vite';
  11. import { visualizer } from 'rollup-plugin-visualizer';
  12. import viteCompression from 'vite-plugin-compression';
  13. import { createHtmlPlugin } from 'vite-plugin-html';
  14. import { name } from './package.json';
  15. export default defineConfig(({ command, mode }) => {
  16. // 本地代理
  17. const proxy = {
  18. '/apictis': {
  19. // target: 'https://saictl.szairport.com', // prod
  20. // target: 'http://192.168.40.136:7002', // test
  21. target: 'http://172.16.46.110:7002', // dev
  22. // target: 'http://192.168.40.106:7002', // tb
  23. // target: 'http://192.168.40.125:7002', // lqw
  24. changeOrigin: true,
  25. rewrite: (path) => path.replace(/^\/apictis/, ''),
  26. },
  27. };
  28. const plugins = [
  29. viteCompression(),
  30. createHtmlPlugin({
  31. minify: true,
  32. inject: {
  33. data: {
  34. title: name,
  35. },
  36. },
  37. }),
  38. vue({
  39. reactivityTransform: true,
  40. }),
  41. vueJsx(),
  42. vitePluginCommonjs(),
  43. // VueSetupExtend(),
  44. AutoImport({
  45. // 可以自定义文件生成的位置,默认是根目录下,使用ts的建议放src目录下
  46. dts: 'src/auto-imports.d.ts',
  47. imports: ['vue'],
  48. // 解决eslint报错问题
  49. eslintrc: {
  50. enabled: true,
  51. },
  52. }),
  53. createSvgIconsPlugin({
  54. // 指定需要缓存的图标文件夹
  55. iconDirs: [resolve(process.cwd(), 'src/icons')],
  56. // 指定symbolId格式
  57. symbolId: 'icon-[dir]-[name]',
  58. }),
  59. eslint({
  60. include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
  61. exclude: ['node_modules'],
  62. }),
  63. ];
  64. if (process.env.report) {
  65. plugins.push(
  66. visualizer({ open: true, brotliSize: true, filename: 'report.html' })
  67. );
  68. }
  69. return {
  70. base: './',
  71. server: {
  72. proxy,
  73. },
  74. build: {
  75. reportCompressedSize: false,
  76. rollupOptions: {
  77. output: {
  78. manualChunks: {
  79. echarts: ['echarts', 'vue-echarts'],
  80. i18n: ['vue-i18n'],
  81. arcoDesign: ['@arco-design/web-vue'],
  82. dayjs: ['dayjs'],
  83. },
  84. },
  85. },
  86. },
  87. plugins,
  88. resolve: {
  89. alias: [
  90. {
  91. find: '@',
  92. replacement: resolve(__dirname, 'src'),
  93. },
  94. ],
  95. extensions: ['.ts', '.js'],
  96. },
  97. css: {
  98. preprocessorOptions: {
  99. less: {
  100. modifyVars: {
  101. // 'arcoblue-6': '#1b1b1b',
  102. },
  103. javascriptEnabled: true,
  104. },
  105. },
  106. },
  107. define: {
  108. 'process.env': {},
  109. },
  110. test: {},
  111. };
  112. });