vite.config.js 4.6 KB

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