vite.config.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import vueJsx from '@vitejs/plugin-vue-jsx';
  4. import { registerSW } from 'virtual:pwa-register';
  5. import Components from 'unplugin-vue-components/vite';
  6. import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
  7. // import viteESLint from 'vite-plugin-eslint';
  8. import legacyPlugin from '@vitejs/plugin-legacy';
  9. import { VitePWA } from 'vite-plugin-pwa';
  10. // 引入等比适配插件
  11. import px2rem from 'postcss-px2rem';
  12. // 配置基本大小
  13. const postcss = px2rem({
  14. // 基准大小 baseSize,需要和rem.js中相同
  15. remUnit: 16
  16. });
  17. // eslint-disable-next-line @typescript-eslint/no-var-requires
  18. const path = require('path');
  19. function resolve(dir: string) {
  20. return path.join(__dirname, dir);
  21. }
  22. // https://vitejs.dev/config/
  23. // https://github.com/vitejs/vite/issues/1930 .env
  24. // const proxyUrl = 'https://dev.kt.colexiu.com/';
  25. const proxyUrl = 'https://test.lexiaoya.cn';
  26. export default defineConfig({
  27. base: './',
  28. plugins: [
  29. vue(),
  30. vueJsx(),
  31. // viteESLint(),
  32. Components({
  33. dts: true,
  34. resolvers: [NaiveUiResolver()]
  35. }),
  36. legacyPlugin({
  37. targets: ['defaults', 'not IE 11'],
  38. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  39. renderLegacyChunks: true,
  40. polyfills: [
  41. 'es.symbol',
  42. 'es.promise',
  43. 'es.promise.finally',
  44. 'es/map',
  45. 'es/set',
  46. 'es.array.filter',
  47. 'es.array.for-each',
  48. 'es.array.flat-map',
  49. 'es.object.define-properties',
  50. 'es.object.define-property',
  51. 'es.object.get-own-property-descriptor',
  52. 'es.object.get-own-property-descriptors',
  53. 'es.object.keys',
  54. 'es.object.to-string',
  55. 'web.dom-collections.for-each',
  56. 'esnext.global-this',
  57. 'esnext.string.match-all'
  58. ]
  59. }),
  60. VitePWA({
  61. registerType: 'autoUpdate',
  62. includeAssets: ['./logo.png'],
  63. manifest: {
  64. name: '酷乐秀-音乐数字课堂',
  65. short_name: '音乐数字课堂',
  66. theme_color: '#E8EAED',
  67. icons: [
  68. {
  69. src: './logo.png',
  70. sizes: '192x192',
  71. type: 'image/png'
  72. },
  73. {
  74. src: './logo.png',
  75. sizes: '512x512',
  76. type: 'image/png'
  77. },
  78. {
  79. src: './logo.png',
  80. sizes: '512x512',
  81. type: 'image/png',
  82. purpose: 'any maskable'
  83. }
  84. ],
  85. prefer_related_applications: false,
  86. related_applications: [
  87. {
  88. platform: 'webapp',
  89. id: '1.0.0',
  90. url: './manifest.webmanifest'
  91. }
  92. ]
  93. },
  94. devOptions: {
  95. enabled: true
  96. }
  97. })
  98. ],
  99. build: {
  100. target: 'es2015'
  101. },
  102. resolve: {
  103. alias: {
  104. '@': resolve('./src'),
  105. '@common': resolve('./src/common'),
  106. '@components': resolve('./src/components'),
  107. '@store': resolve('./src/store'),
  108. '@views': resolve('./src/views')
  109. }
  110. },
  111. server: {
  112. host: '0.0.0.0',
  113. port: 5002,
  114. strictPort: true,
  115. cors: true,
  116. https: false,
  117. proxy: {
  118. '/edu-app': {
  119. target: proxyUrl,
  120. changeOrigin: true
  121. }
  122. }
  123. }
  124. });