vite.config.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import path from "path";
  2. import { UserConfigExport, ConfigEnv } from "vite";
  3. import vueJsx from "@vitejs/plugin-vue-jsx";
  4. import vue from "@vitejs/plugin-vue";
  5. import svgLoader from "vite-svg-loader";
  6. import Components from "unplugin-vue-components/vite";
  7. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  8. import ElementPlus from "unplugin-element-plus/vite";
  9. import { LOGIN_URL,BASE_URL} from "./src/utils/constant"
  10. import styleImport from "vite-plugin-style-import";
  11. /**
  12. * @type {import('vite').UserConfig}
  13. * @link {https://vitejs.cn/config/}
  14. */
  15. export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  16. return {
  17. root: process.cwd(),
  18. base: "./",
  19. server: {
  20. host: "localhost",
  21. open: true,
  22. port: 8000,
  23. // strictPort: true,
  24. https: false,
  25. force: true,
  26. proxy: {
  27. "/api": {
  28. // target: "http://sqpcbg.xt.wenhq.top:8083/",
  29. target:BASE_URL,
  30. changeOrigin: true,
  31. rewrite: (path) => path.replace(/^\/api/, ''),
  32. },
  33. },
  34. },
  35. resolve: {
  36. alias: {
  37. "@": path.resolve(__dirname, "./src"),
  38. },
  39. },
  40. css: {
  41. modules: {
  42. localsConvention: "camelCase", // 默认只支持驼峰,修改为同事支持横线和驼峰
  43. },
  44. preprocessorOptions: {
  45. scss: {
  46. /**
  47. * TODO:// 目前按需加载时修改主题色会报错
  48. * 官方修复后在进行按需加载
  49. * @link {https://github.com/element-plus/element-plus/issues/2724}
  50. *
  51. * */
  52. // additionalData: `@use "@/styles/element/index.scss" as *;`,
  53. },
  54. // scss: { additionalData: `@import "@/styles/vars.scss";` },
  55. // less: {
  56. // javascriptEnabled: true,
  57. // additionalData: `@import "@/styles/default.less";`,
  58. // },
  59. },
  60. },
  61. plugins: [
  62. vue(),
  63. vueJsx({
  64. // options are passed on to @vue/babel-plugin-jsx
  65. }),
  66. svgLoader(),
  67. // ElementPlus({ useSource: true }),
  68. styleImport({
  69. libs: [
  70. {
  71. libraryName: "vant",
  72. esModule: true,
  73. resolveStyle: (name) => `vant/es/${name}/style`,
  74. },
  75. ],
  76. }),
  77. ],
  78. };
  79. };