vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
  6. import viteESLint from 'vite-plugin-eslint';
  7. import legacyPlugin from '@vitejs/plugin-legacy';
  8. import { VitePWA } from 'vite-plugin-pwa';
  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://dev.kt.colexiu.com/';
  17. // const proxyUrl = 'https://test.lexiaoya.cn';
  18. export default defineConfig({
  19. base: './',
  20. plugins: [
  21. vue(),
  22. vueJsx(),
  23. viteESLint(),
  24. Components({
  25. dts: true,
  26. resolvers: [NaiveUiResolver()]
  27. }),
  28. legacyPlugin({
  29. targets: ['defaults', 'not IE 11'],
  30. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  31. renderLegacyChunks: true,
  32. polyfills: [
  33. 'es.symbol',
  34. 'es.promise',
  35. 'es.promise.finally',
  36. 'es/map',
  37. 'es/set',
  38. 'es.array.filter',
  39. 'es.array.for-each',
  40. 'es.array.flat-map',
  41. 'es.object.define-properties',
  42. 'es.object.define-property',
  43. 'es.object.get-own-property-descriptor',
  44. 'es.object.get-own-property-descriptors',
  45. 'es.object.keys',
  46. 'es.object.to-string',
  47. 'web.dom-collections.for-each',
  48. 'esnext.global-this',
  49. 'esnext.string.match-all'
  50. ]
  51. }),
  52. VitePWA({
  53. registerType: 'autoUpdate',
  54. includeAssets: ['favicon.svg'],
  55. manifest: {
  56. name: '酷乐秀-课堂乐器',
  57. short_name: '课堂乐器',
  58. theme_color: '#fff',
  59. icons: [
  60. {
  61. src: './public/logo.png',
  62. sizes: '192x192',
  63. type: 'image/png'
  64. },
  65. {
  66. src: './public/logo.png',
  67. sizes: '512x512',
  68. type: 'image/png'
  69. },
  70. {
  71. src: './public/logo.png',
  72. sizes: '512x512',
  73. type: 'image/png',
  74. purpose: 'any maskable'
  75. }
  76. ]
  77. },
  78. devOptions: {
  79. enabled: true
  80. }
  81. })
  82. ],
  83. build: {
  84. target: 'es2015'
  85. },
  86. resolve: {
  87. alias: {
  88. '@': resolve('./src'),
  89. '@common': resolve('./src/common'),
  90. '@components': resolve('./src/components'),
  91. '@store': resolve('./src/store'),
  92. '@views': resolve('./src/views')
  93. }
  94. },
  95. server: {
  96. host: '0.0.0.0',
  97. port: 5002,
  98. strictPort: true,
  99. cors: true,
  100. https: false,
  101. proxy: {
  102. '/edu-app': {
  103. target: proxyUrl,
  104. changeOrigin: true
  105. }
  106. }
  107. }
  108. });