vite.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import vueJsx from '@vitejs/plugin-vue-jsx';
  4. import Components from 'unplugin-vue-components/vite';
  5. import { VantResolver } from 'unplugin-vue-components/resolvers';
  6. import viteESLint from 'vite-plugin-eslint';
  7. import legacy from '@vitejs/plugin-legacy';
  8. import { terser } from 'rollup-plugin-terser';
  9. // eslint-disable-next-line @typescript-eslint/no-var-requires
  10. const path = require('path');
  11. function resolve(dir: string) {
  12. return path.join(__dirname, dir);
  13. }
  14. // https://vitejs.dev/config/
  15. // https://github.com/vitejs/vite/issues/1930 .env
  16. const proxyUrl = 'https://test.gym.lexiaoya.cn';
  17. export default defineConfig({
  18. base: './',
  19. plugins: [
  20. legacy({
  21. targets: ['chrome 52'],
  22. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  23. renderLegacyChunks: true,
  24. polyfills: [
  25. 'es.symbol',
  26. 'es.promise',
  27. 'es.promise.finally',
  28. 'es/map',
  29. 'es/set',
  30. 'es.array.filter',
  31. 'es.array.for-each',
  32. 'es.array.flat-map',
  33. 'es.object.define-properties',
  34. 'es.object.define-property',
  35. 'es.object.get-own-property-descriptor',
  36. 'es.object.get-own-property-descriptors',
  37. 'es.object.keys',
  38. 'es.object.to-string',
  39. 'web.dom-collections.for-each',
  40. 'esnext.global-this',
  41. 'esnext.string.match-all'
  42. ]
  43. }),
  44. vue(),
  45. vueJsx(),
  46. viteESLint(),
  47. Components({
  48. resolvers: [VantResolver()]
  49. })
  50. ],
  51. build: {
  52. target: 'es2015',
  53. rollupOptions: {
  54. plugins: [terser()]
  55. },
  56. minify: 'terser',
  57. terserOptions: {
  58. compress: {
  59. drop_console: true,
  60. drop_debugger: true
  61. },
  62. ie8: true,
  63. output: {
  64. comments: true
  65. }
  66. }
  67. // reportCompressedSize: false
  68. },
  69. resolve: {
  70. alias: {
  71. '@': resolve('./src'),
  72. '@common': resolve('./src/common'),
  73. '@components': resolve('./src/components'),
  74. '@store': resolve('./src/store'),
  75. '@views': resolve('./src/views')
  76. }
  77. },
  78. server: {
  79. host: '0.0.0.0',
  80. port: 9005,
  81. strictPort: true,
  82. cors: true,
  83. https: false,
  84. proxy: {
  85. '/api-student': {
  86. target: proxyUrl,
  87. changeOrigin: true
  88. },
  89. '/api-teacher': {
  90. target: proxyUrl,
  91. changeOrigin: true
  92. },
  93. '/api-admin': {
  94. target: proxyUrl,
  95. changeOrigin: true
  96. },
  97. '/api-auth': {
  98. target: proxyUrl,
  99. changeOrigin: true
  100. }
  101. }
  102. }
  103. });