vite.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { resolve } from "path";
  2. import { defineConfig } from "vite";
  3. // import minipic from "vite-plugin-minipic";
  4. import vue from "@vitejs/plugin-vue";
  5. import vueJsx from "@vitejs/plugin-vue-jsx";
  6. import AutoImport from "unplugin-auto-import/vite";
  7. import Components from "unplugin-vue-components/vite";
  8. import Icons from "unplugin-icons/vite";
  9. // import IconsResolver from 'unplugin-icons/resolver'
  10. // import viteCompression from 'vite-plugin-compression'
  11. import basicSsl from "@vitejs/plugin-basic-ssl";
  12. import deletePlugin from "rollup-plugin-delete";
  13. import Unocss from "unocss/vite";
  14. import minipic from "vite-plugin-imagemin";
  15. import vitePluginStyleVwLoader from "vite-plugin-style-vw-loader";
  16. import { VantResolver } from "@vant/auto-import-resolver";
  17. // import { visualizer } from 'rollup-plugin-visualizer'
  18. // https://vitejs.dev/config/
  19. export default ({ mode }) => {
  20. // const env = loadEnv(mode, process.cwd())
  21. return defineConfig({
  22. base: "/foreground/",
  23. build: {
  24. outDir: "bkq-dist",
  25. sourcemap: false,
  26. minify: true,
  27. emptyOutDir: true,
  28. rollupOptions: {
  29. output: {
  30. chunkFileNames: "js/[hash].js",
  31. entryFileNames: "js/[hash].js",
  32. assetFileNames: (assetsFile) => {
  33. if (/\.(vue|scss)$/i.test(assetsFile.name)) {
  34. return "del/[name]-[hash].[ext]";
  35. } else {
  36. return "static/[hash].[ext]";
  37. }
  38. },
  39. },
  40. },
  41. },
  42. plugins: [
  43. vitePluginStyleVwLoader({
  44. unitToConvert: "px",
  45. viewportWidth: 1600,
  46. unitPrecision: 5,
  47. viewportUnit: "vw",
  48. fontViewportUnit: "vw",
  49. minPixelValue: 1,
  50. }),
  51. vue(),
  52. vueJsx(),
  53. basicSsl(),
  54. Unocss(),
  55. AutoImport({
  56. imports: [
  57. "vue",
  58. "vue-router",
  59. "pinia",
  60. "@vueuse/core",
  61. {
  62. "@/api": ["useRequest"],
  63. },
  64. {
  65. "@/locales": ["useI18n", "locale"],
  66. },
  67. ],
  68. eslintrc: {
  69. enabled: false, // Default `false`
  70. filepath: "./.eslintrc-auto-import.json", // Default `./.eslintrc-auto-import.json`
  71. globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
  72. },
  73. resolvers: [VantResolver()],
  74. }),
  75. Components({
  76. dirs: ["src/components"],
  77. dts: false,
  78. resolvers: [
  79. VantResolver(),
  80. // IconsResolver({
  81. // prefix: "i",
  82. // alias: {
  83. // system: "system-uicons",
  84. // },
  85. // }),
  86. ],
  87. include: [/\.vue$/, /\.vue\?vue/, /\.jsx$/],
  88. }),
  89. Icons({
  90. compiler: "vue3",
  91. }),
  92. deletePlugin({
  93. targets: ["bkq-dist/del"],
  94. hook: "writeBundle",
  95. }),
  96. // visualizer({
  97. // emitFile: false,
  98. // file: 'stats.html',
  99. // open: true
  100. // }),
  101. // IconsResolver({
  102. // prefix: 'i',
  103. // alias: {
  104. // system: 'system-uicons'
  105. // }
  106. // }),
  107. minipic({
  108. /** 无损压缩配置,无损压缩下图片质量不会变差 */
  109. optipng: {
  110. optimizationLevel: 7, // 选择 0 到 7 之间的优化级别
  111. },
  112. /** 有损压缩配置,有损压缩下图片质量可能会变差 */
  113. pngquant: {
  114. quality: [0.8, 0.9], // 压缩质量
  115. speed: 4, // 压缩速度,范围 0~11
  116. },
  117. gifsicle: {
  118. optimizationLevel: 7,
  119. interlaced: false,
  120. },
  121. mozjpeg: {
  122. quality: 85, // 压缩质量
  123. },
  124. svgo: {
  125. plugins: [
  126. { name: "removeViewBox" },
  127. { name: "removeEmptyAttrs", active: false },
  128. ],
  129. },
  130. /** 是否禁用 */
  131. disable: false,
  132. /** 是否在控制台输出压缩结果 */
  133. verbose: true,
  134. }),
  135. ],
  136. resolve: {
  137. alias: {
  138. "@": resolve(__dirname, "src"),
  139. "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
  140. },
  141. },
  142. css: {
  143. preprocessorOptions: {
  144. scss: {
  145. api: 'modern-compiler',
  146. //忽略警告提示
  147. silenceDeprecations: ['legacy-js-api', 'import']
  148. }
  149. }
  150. },
  151. define: {
  152. __DEV__: mode === "development",
  153. __TEST__: mode === "test",
  154. },
  155. // server:{
  156. // proxy:{
  157. // '/alarm':{
  158. // target: 'https://127.0.0.1',
  159. // changeOrigin: true,
  160. // rewrite: (path) => path.replace(/^api/, ''),
  161. // }
  162. // }
  163. // }
  164. });
  165. };