vite.config.ts 4.2 KB

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