vite.config.ts 1.6 KB

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