vite.config.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. import versionUpdatePlugin from './src/plugins/version';
  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.kt.colexiu.com';
  26. const proxyUrl = 'https://test.lexiaoya.cn';
  27. // const proxyUrl = 'http://192.168.3.14:7989';
  28. const now = new Date().getTime();
  29. export default defineConfig(() => {
  30. return {
  31. base: './',
  32. plugins: [
  33. vue(),
  34. vueJsx(),
  35. // viteESLint(),
  36. Components({
  37. dts: true,
  38. resolvers: [NaiveUiResolver()]
  39. }),
  40. legacyPlugin({
  41. targets: ['defaults', 'not IE 11'],
  42. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  43. renderLegacyChunks: true,
  44. polyfills: [
  45. 'es.symbol',
  46. 'es.promise',
  47. 'es.promise.finally',
  48. 'es/map',
  49. 'es/set',
  50. 'es.array.filter',
  51. 'es.array.for-each',
  52. 'es.array.flat-map',
  53. 'es.object.define-properties',
  54. 'es.object.define-property',
  55. 'es.object.get-own-property-descriptor',
  56. 'es.object.get-own-property-descriptors',
  57. 'es.object.keys',
  58. 'es.object.to-string',
  59. 'web.dom-collections.for-each',
  60. 'esnext.global-this',
  61. 'esnext.string.match-all'
  62. ]
  63. }),
  64. VitePWA({
  65. registerType: 'autoUpdate',
  66. includeAssets: ['./logo.png'],
  67. workbox: {
  68. skipWaiting: true
  69. // runtimeCaching: [
  70. // {
  71. // urlPattern: /(.*?)\.(js|css|ts|tsx|html)/, // js /css /ts静态资源缓存
  72. // handler: 'NetworkOnly',
  73. // options: {
  74. // cacheName: 'js-css-cache'
  75. // }
  76. // },
  77. // {
  78. // urlPattern: /.*\.html.*/,
  79. // handler: 'NetworkOnly',
  80. // options: {
  81. // cacheName: 'wisbayar-html',
  82. // expiration: {
  83. // maxEntries: 20,
  84. // maxAgeSeconds: 30 * 24 * 60 * 60
  85. // },
  86. // cacheableResponse: {
  87. // statuses: [200]
  88. // }
  89. // }
  90. // }
  91. // ]
  92. },
  93. manifest: {
  94. name: '酷乐秀-音乐数字课堂',
  95. short_name: '音乐数字课堂',
  96. theme_color: '#E8EAED',
  97. display: 'fullscreen',
  98. icons: [
  99. {
  100. src: './logo.png',
  101. sizes: '192x192',
  102. type: 'image/png'
  103. },
  104. {
  105. src: './logo.png',
  106. sizes: '512x512',
  107. type: 'image/png'
  108. },
  109. {
  110. src: './logo.png',
  111. sizes: '512x512',
  112. type: 'image/png',
  113. purpose: 'any maskable'
  114. }
  115. ],
  116. prefer_related_applications: false,
  117. related_applications: [
  118. {
  119. platform: 'webapp',
  120. id: '1.0.0',
  121. url: './manifest.webmanifest'
  122. }
  123. ]
  124. },
  125. devOptions: {
  126. enabled: true
  127. }
  128. }),
  129. versionUpdatePlugin({
  130. version: now
  131. })
  132. ],
  133. define: {
  134. // 定义全局变量
  135. __APP_VERSION__: now
  136. },
  137. build: {
  138. target: 'es2015',
  139. rollupOptions: {
  140. output: {
  141. entryFileNames: `[name]-[hash]-${now}.js`,
  142. chunkFileNames: `[name]-[hash]-${now}.js`,
  143. assetFileNames: `[name]-[hash].[ext]`
  144. }
  145. }
  146. },
  147. resolve: {
  148. alias: {
  149. '@': resolve('./src'),
  150. '@common': resolve('./src/common'),
  151. '@components': resolve('./src/components'),
  152. '@store': resolve('./src/store'),
  153. '@views': resolve('./src/views')
  154. }
  155. },
  156. server: {
  157. host: '0.0.0.0',
  158. port: 5002,
  159. strictPort: true,
  160. cors: true,
  161. https: false,
  162. proxy: {
  163. '/edu-app': {
  164. target: proxyUrl,
  165. changeOrigin: true
  166. }
  167. }
  168. }
  169. };
  170. });