vite.config.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // 引入等比适配插件
  10. import px2rem from 'postcss-px2rem';
  11. // 配置基本大小
  12. const postcss = px2rem({
  13. // 基准大小 baseSize,需要和rem.js中相同
  14. remUnit: 16
  15. });
  16. // eslint-disable-next-line @typescript-eslint/no-var-requires
  17. const path = require('path');
  18. function resolve(dir: string) {
  19. return path.join(__dirname, dir);
  20. }
  21. // https://vitejs.dev/config/
  22. // https://github.com/vitejs/vite/issues/1930 .env
  23. // const proxyUrl = 'https://dev.kt.colexiu.com/';
  24. const proxyUrl = 'https://test.lexiaoya.cn';
  25. export default defineConfig({
  26. base: './',
  27. plugins: [
  28. vue(),
  29. vueJsx(),
  30. // viteESLint(),
  31. Components({
  32. dts: true,
  33. resolvers: [NaiveUiResolver()]
  34. }),
  35. legacyPlugin({
  36. targets: ['defaults', 'not IE 11'],
  37. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  38. renderLegacyChunks: true,
  39. polyfills: [
  40. 'es.symbol',
  41. 'es.promise',
  42. 'es.promise.finally',
  43. 'es/map',
  44. 'es/set',
  45. 'es.array.filter',
  46. 'es.array.for-each',
  47. 'es.array.flat-map',
  48. 'es.object.define-properties',
  49. 'es.object.define-property',
  50. 'es.object.get-own-property-descriptor',
  51. 'es.object.get-own-property-descriptors',
  52. 'es.object.keys',
  53. 'es.object.to-string',
  54. 'web.dom-collections.for-each',
  55. 'esnext.global-this',
  56. 'esnext.string.match-all'
  57. ]
  58. }),
  59. VitePWA({
  60. registerType: 'autoUpdate',
  61. includeAssets: ['./logo.png'],
  62. workbox: {
  63. // globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
  64. runtimeCaching: [
  65. {
  66. urlPattern: /classroom/i, // 接口缓存 此处填你想缓存的接口正则匹配
  67. handler: 'NetworkFirst',
  68. options: {
  69. cacheName: 'interface-cache'
  70. }
  71. },
  72. {
  73. urlPattern: /(.*?)\.(js|css|ts)/, // js /css /ts静态资源缓存
  74. handler: 'NetworkFirst',
  75. options: {
  76. cacheName: 'js-css-cache'
  77. }
  78. },
  79. {
  80. urlPattern: /(.*?)\.(png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/, // 图片缓存
  81. handler: 'NetworkFirst',
  82. options: {
  83. cacheName: 'image-cache'
  84. }
  85. }
  86. ]
  87. },
  88. manifest: {
  89. name: '酷乐秀-音乐数字课堂',
  90. short_name: '音乐数字课堂',
  91. theme_color: '#E8EAED',
  92. display: 'fullscreen',
  93. icons: [
  94. {
  95. src: './logo.png',
  96. sizes: '192x192',
  97. type: 'image/png'
  98. },
  99. {
  100. src: './logo.png',
  101. sizes: '512x512',
  102. type: 'image/png'
  103. },
  104. {
  105. src: './logo.png',
  106. sizes: '512x512',
  107. type: 'image/png',
  108. purpose: 'any maskable'
  109. }
  110. ],
  111. prefer_related_applications: false,
  112. related_applications: [
  113. {
  114. platform: 'webapp',
  115. id: '1.0.0',
  116. url: './manifest.webmanifest'
  117. }
  118. ]
  119. },
  120. devOptions: {
  121. enabled: true
  122. }
  123. })
  124. ],
  125. build: {
  126. target: 'es2015'
  127. },
  128. resolve: {
  129. alias: {
  130. '@': resolve('./src'),
  131. '@common': resolve('./src/common'),
  132. '@components': resolve('./src/components'),
  133. '@store': resolve('./src/store'),
  134. '@views': resolve('./src/views')
  135. }
  136. },
  137. server: {
  138. host: '0.0.0.0',
  139. port: 5002,
  140. strictPort: true,
  141. cors: true,
  142. https: false,
  143. proxy: {
  144. '/edu-app': {
  145. target: proxyUrl,
  146. changeOrigin: true
  147. }
  148. }
  149. }
  150. });