vite.config.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import vueJsx from "@vitejs/plugin-vue-jsx";
  4. import Components from "unplugin-vue-components/vite";
  5. import { VantResolver } from "unplugin-vue-components/resolvers";
  6. import postcssPxtorem from "postcss-pxtorem";
  7. import { createStyleImportPlugin } from "vite-plugin-style-import";
  8. import legacy from "@vitejs/plugin-legacy";
  9. import path from "path";
  10. const proxyUrl = "https://dev.colexiu.com/";
  11. // const proxyUrl = "https://online.colexiu.com/";
  12. const resolve = (dir: string) => path.join(__dirname, dir)
  13. // https://vitejs.dev/config/
  14. export default defineConfig({
  15. base: './',
  16. plugins: [
  17. vue(),
  18. vueJsx(),
  19. legacy({
  20. targets: ["> 0.25%, not dead"],
  21. ignoreBrowserslistConfig: true,
  22. }),
  23. Components({
  24. resolvers: [VantResolver()],
  25. }),
  26. createStyleImportPlugin({
  27. libs: [
  28. {
  29. libraryName: "vant",
  30. esModule: true,
  31. resolveStyle: (name) => `../es/${name}/style/index`,
  32. },
  33. ],
  34. }),
  35. ],
  36. css: {
  37. postcss: {
  38. plugins: [
  39. postcssPxtorem({
  40. rootValue: 37.5, // 1rem的大小
  41. propList: ["*"], // 需要转换的属性,这里选择全部都进行转换
  42. }),
  43. ],
  44. },
  45. },
  46. resolve: {
  47. alias: {
  48. "@": resolve('./src'),
  49. },
  50. },
  51. server: {
  52. host: "0.0.0.0",
  53. port: 5050,
  54. // open: true,
  55. proxy: {
  56. "/api-website": {
  57. target: proxyUrl,
  58. changeOrigin: true,
  59. },
  60. },
  61. },
  62. build: {
  63. terserOptions: {
  64. //打包后移除console和注释
  65. compress: {
  66. drop_console: true,
  67. drop_debugger: true,
  68. },
  69. },
  70. },
  71. });