vite.config.ts 5.2 KB

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