vite.config.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { defineConfig } from "vite";
  2. import path from "path";
  3. import vue from "@vitejs/plugin-vue";
  4. import Components from "unplugin-vue-components/vite";
  5. import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
  6. import vueSetupExtend from "vite-plugin-vue-setup-extend";
  7. import {
  8. createStyleImportPlugin,
  9. AndDesignVueResolve,
  10. } from "vite-plugin-style-import";
  11. import AutoImport from "unplugin-auto-import/vite";
  12. import rollup from "./rollup";
  13. import viteCompression from "vite-plugin-compression";
  14. import theme from "./src/config/theme";
  15. import autoprefixer from "autoprefixer";
  16. import eslint from "vite-plugin-eslint";
  17. export default defineConfig({
  18. plugins: [
  19. vue(),
  20. eslint({
  21. cache: false,
  22. fix: true,
  23. }),
  24. viteCompression(),
  25. vueSetupExtend(),
  26. Components({
  27. resolvers: [
  28. AntDesignVueResolver({
  29. importStyle: "less",
  30. }),
  31. ],
  32. }),
  33. createStyleImportPlugin({
  34. resolves: [AndDesignVueResolve()],
  35. }),
  36. AutoImport({
  37. imports: ["vue", "pinia", "vue-router"], //需要自动引入的包
  38. dts: "./auto.js", //生成文件路径
  39. vueTemplate: true, //Auto import inside Vue template,
  40. }),
  41. ],
  42. build: {
  43. sourcemap: true,
  44. cssTarget: "chrome61",
  45. outDir: "dist",
  46. rollupOptions: rollup,
  47. minify: "terser",
  48. terserOptions: {
  49. compress: {
  50. drop_console: true, //去掉所有console
  51. drop_debugger: true, //去掉所有debugger
  52. },
  53. },
  54. },
  55. css: {
  56. preprocessorOptions: {
  57. less: {
  58. modifyVars: theme,
  59. javascriptEnabled: true,
  60. },
  61. scss: {
  62. additionalData: `
  63. @import "@/theme/theme.scss";
  64. @import "@/theme/scroll.scss";
  65. @import "@/assets/font/iconfont.scss";
  66. @import "@/theme/antd.scss";
  67. `,
  68. },
  69. },
  70. postcss: {
  71. plugins: [autoprefixer()],
  72. },
  73. },
  74. server: {
  75. host: "0.0.0.0",
  76. port: 8080,
  77. proxy: {
  78. "/api": {
  79. target: "https://tp5.rungyun.cn", // 目标服务器地址
  80. ws: true, // 是否启用 WebSocket
  81. changeOrigin: true, // 是否修改请求头中的 Origin 字段
  82. rewrite: (path) => path.replace(/^\/api/, ""),
  83. },
  84. },
  85. },
  86. resolve: {
  87. alias: {
  88. "@": path.join(__dirname, "src"),
  89. },
  90. },
  91. });