vite.config.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueDevTools from 'vite-plugin-vue-devtools'
  5. import pxtorem from 'postcss-pxtorem'
  6. // https://vite.dev/config/
  7. export default defineConfig(({ mode }) => {
  8. // eslint-disable-next-line no-undef
  9. const env = loadEnv(mode, process.cwd())
  10. console.log(env, 7777)
  11. return {
  12. base: env.VITE_PUBLIC_PATH || '/',
  13. plugins: [
  14. vue(),
  15. ],
  16. css: {
  17. postcss: {
  18. plugins: [
  19. pxtorem({
  20. // 以 2160 设计稿为基准,1rem = 216px(结合脚本按视口宽度动态缩放)
  21. rootValue: 216,
  22. propList: ['*'],
  23. replace: true,
  24. mediaQuery: false,
  25. exclude: /node_modules/i,
  26. }),
  27. ],
  28. },
  29. },
  30. resolve: {
  31. alias: {
  32. '@': fileURLToPath(new URL('./src', import.meta.url))
  33. },
  34. },
  35. server: {
  36. host: '0.0.0.0',
  37. port: 5200,
  38. open: true,
  39. proxy: {
  40. '/hyb': {
  41. target: env.VITE_PROXY_TARGET,
  42. changeOrigin: true,
  43. },
  44. },
  45. },
  46. }
  47. })