vite.config.ts 4.2 KB

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