vite.config.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. <<<<<<< HEAD
  25. // const proxyUrl = 'https://dev.kt.colexiu.com/';
  26. // const proxyUrl = 'http://192.168.3.14:7989';
  27. const proxyUrl = 'https://test.lexiaoya.cn';
  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. const proxyUrl = 'https://dev.kt.colexiu.com/';
  64. // const proxyUrl = 'https://test.lexiaoya.cn';
  65. export default defineConfig({
  66. base: './',
  67. plugins: [
  68. vue(),
  69. vueJsx(),
  70. // viteESLint(),
  71. Components({
  72. dts: true,
  73. resolvers: [NaiveUiResolver()]
  74. }),
  75. legacyPlugin({
  76. targets: ['defaults', 'not IE 11'],
  77. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  78. renderLegacyChunks: true,
  79. polyfills: [
  80. 'es.symbol',
  81. 'es.promise',
  82. 'es.promise.finally',
  83. 'es/map',
  84. 'es/set',
  85. 'es.array.filter',
  86. 'es.array.for-each',
  87. 'es.array.flat-map',
  88. 'es.object.define-properties',
  89. 'es.object.define-property',
  90. 'es.object.get-own-property-descriptor',
  91. 'es.object.get-own-property-descriptors',
  92. 'es.object.keys',
  93. 'es.object.to-string',
  94. 'web.dom-collections.for-each',
  95. 'esnext.global-this',
  96. 'esnext.string.match-all'
  97. ]
  98. }),
  99. VitePWA({
  100. registerType: 'autoUpdate',
  101. includeAssets: ['./logo.png'],
  102. // workbox: {
  103. // runtimeCaching: [
  104. // {
  105. // urlPattern: /(.*?)\.(js|css|ts|tsx|html)/, // js /css /ts静态资源缓存
  106. // handler: 'NetworkOnly',
  107. // options: {
  108. // cacheName: 'js-css-cache'
  109. // }
  110. // },
  111. // {
  112. // urlPattern: /.*\.html.*/,
  113. // handler: 'NetworkOnly',
  114. // options: {
  115. // cacheName: 'wisbayar-html',
  116. // expiration: {
  117. // maxEntries: 20,
  118. // maxAgeSeconds: 30 * 24 * 60 * 60
  119. // },
  120. // cacheableResponse: {
  121. // statuses: [200]
  122. // }
  123. // }
  124. // }
  125. // ]
  126. // },
  127. manifest: {
  128. name: '酷乐秀-音乐数字课堂',
  129. short_name: '音乐数字课堂',
  130. theme_color: '#E8EAED',
  131. display: 'fullscreen',
  132. icons: [
  133. {
  134. src: './logo.png',
  135. sizes: '192x192',
  136. type: 'image/png'
  137. },
  138. {
  139. src: './logo.png',
  140. sizes: '512x512',
  141. type: 'image/png'
  142. },
  143. {
  144. src: './logo.png',
  145. sizes: '512x512',
  146. type: 'image/png',
  147. purpose: 'any maskable'
  148. }
  149. ],
  150. prefer_related_applications: false,
  151. related_applications: [
  152. {
  153. platform: 'webapp',
  154. id: '1.0.0',
  155. url: './manifest.webmanifest'
  156. }
  157. >>>>>>> iteration-20231220
  158. ]
  159. }),
  160. VitePWA({
  161. registerType: 'autoUpdate',
  162. includeAssets: ['./logo.png'],
  163. workbox: {
  164. skipWaiting: true
  165. // runtimeCaching: [
  166. // {
  167. // urlPattern: /(.*?)\.(js|css|ts|tsx|html)/, // js /css /ts静态资源缓存
  168. // handler: 'NetworkOnly',
  169. // options: {
  170. // cacheName: 'js-css-cache'
  171. // }
  172. // },
  173. // {
  174. // urlPattern: /.*\.html.*/,
  175. // handler: 'NetworkOnly',
  176. // options: {
  177. // cacheName: 'wisbayar-html',
  178. // expiration: {
  179. // maxEntries: 20,
  180. // maxAgeSeconds: 30 * 24 * 60 * 60
  181. // },
  182. // cacheableResponse: {
  183. // statuses: [200]
  184. // }
  185. // }
  186. // }
  187. // ]
  188. },
  189. manifest: {
  190. name: '酷乐秀-音乐数字课堂',
  191. short_name: '音乐数字课堂',
  192. theme_color: '#E8EAED',
  193. display: 'fullscreen',
  194. icons: [
  195. {
  196. src: './logo.png',
  197. sizes: '192x192',
  198. type: 'image/png'
  199. },
  200. {
  201. src: './logo.png',
  202. sizes: '512x512',
  203. type: 'image/png'
  204. },
  205. {
  206. src: './logo.png',
  207. sizes: '512x512',
  208. type: 'image/png',
  209. purpose: 'any maskable'
  210. }
  211. ],
  212. prefer_related_applications: false,
  213. related_applications: [
  214. {
  215. platform: 'webapp',
  216. id: '1.0.0',
  217. url: './manifest.webmanifest'
  218. }
  219. ]
  220. },
  221. devOptions: {
  222. enabled: true
  223. }
  224. }),
  225. versionUpdatePlugin({
  226. version: now
  227. })
  228. ],
  229. define: {
  230. // 定义全局变量
  231. __APP_VERSION__: now
  232. },
  233. build: {
  234. target: 'es2015',
  235. rollupOptions: {
  236. output: {
  237. entryFileNames: `[name]-[hash]-${now}.js`,
  238. chunkFileNames: `[name]-[hash]-${now}.js`,
  239. assetFileNames: `[name]-[hash].[ext]`
  240. }
  241. }
  242. },
  243. resolve: {
  244. alias: {
  245. '@': resolve('./src'),
  246. '@common': resolve('./src/common'),
  247. '@components': resolve('./src/components'),
  248. '@store': resolve('./src/store'),
  249. '@views': resolve('./src/views')
  250. }
  251. },
  252. server: {
  253. host: '0.0.0.0',
  254. port: 5002,
  255. strictPort: true,
  256. cors: true,
  257. https: false,
  258. proxy: {
  259. '/edu-app': {
  260. target: proxyUrl,
  261. changeOrigin: true
  262. }
  263. }
  264. }
  265. };
  266. });