vite.config.ts 4.6 KB

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