vite.config.ts 7.2 KB

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