vite.config.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import legacy from '@vitejs/plugin-legacy'
  4. import { resolve } from 'path'
  5. import postcsspxtoviewport from 'postcss-px-to-viewport-8-plugin'
  6. import autoprefixer from 'autoprefixer'
  7. import Components from 'unplugin-vue-components/vite'
  8. import { VantResolver } from 'unplugin-vue-components/resolvers'
  9. import { Plugin as importToCDN } from 'vite-plugin-cdn-import'
  10. function pathResolve(dir) {
  11. // eslint-disable-next-line no-undef
  12. return resolve(__dirname, '.', dir)
  13. }
  14. // https://vitejs.dev/config/
  15. export default defineConfig({
  16. plugins: [
  17. vue(),
  18. importToCDN({
  19. modules: [
  20. {
  21. name: 'md5',
  22. var: 'md5',
  23. path: 'https://cs.wechat.kfzs.com/client/static/js/md5_standard.js'
  24. }
  25. ]
  26. }),
  27. Components({
  28. resolvers: [VantResolver()]
  29. }),
  30. legacy({
  31. targets: ['defaults', 'not IE 11', 'chrome >= 50', 'UCAndroid >= 12'],
  32. additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
  33. renderLegacyChunks: true,
  34. polyfills: [
  35. 'es.symbol',
  36. 'es.array.filter',
  37. 'es.promise',
  38. 'es.promise.finally',
  39. 'es/map',
  40. 'es/set',
  41. 'es.array.for-each',
  42. 'es.object.define-properties',
  43. 'es.object.define-property',
  44. 'es.object.get-own-property-descriptor',
  45. 'es.object.get-own-property-descriptors',
  46. 'es.object.keys',
  47. 'es.object.to-string',
  48. 'web.dom-collections.for-each',
  49. 'esnext.global-this',
  50. 'esnext.string.match-all'
  51. ]
  52. })
  53. ],
  54. server: {
  55. host: '0.0.0.0',
  56. cors: true,
  57. open: true,
  58. port: 5066,
  59. proxy: {
  60. // 跨域前缀写法
  61. '/api': {
  62. target: 'http://192.168.99.223:3000',
  63. changeOrigin: true,
  64. rewrite: (path) => path.replace(/^\/api/, '')
  65. }
  66. }
  67. },
  68. resolve: {
  69. alias: {
  70. '@': pathResolve('src') // 路径别名
  71. },
  72. extensions: ['.js', '.json', '.ts', '.mjs'] // 使用路径别名时想要省略的后缀名,可以自己 增减
  73. },
  74. css: {
  75. postcss: {
  76. plugins: [
  77. autoprefixer({
  78. overrideBrowserslist: [
  79. 'Android 4.1',
  80. 'iOS 7.1',
  81. 'Chrome > 31',
  82. 'ff > 31',
  83. 'ie >= 8'
  84. // 'last 2 versions', // 所有主流浏览器最近2个版本
  85. ],
  86. grid: true
  87. }),
  88. postcsspxtoviewport({
  89. unitToConvert: 'px', // 需要转换的单位,默认为"px"
  90. viewportWidth: 375, // 设计稿的视口宽度
  91. exclude: [/node_modules/], // 解决vant375,设计稿750问题。忽略某些文件夹下的文件或特定文件
  92. unitPrecision: 5, // 单位转换后保留的精度
  93. propList: ['*'], // 能转化为vw的属性列表
  94. viewportUnit: 'vw', // 希望使用的视口单位
  95. fontViewportUnit: 'vw', // 字体使用的视口单位
  96. selectorBlackList: [], // 需要忽略的CSS选择器,不会转为视口单位,使用原有的px等单位。
  97. minPixelValue: 1, // 设置最小的转换数值,如果为1的话,只有大于1的值会被转换
  98. mediaQuery: false, // 媒体查询里的单位是否需要转换单位
  99. replace: true, // 是否直接更换属性值,而不添加备用属性
  100. landscape: false, // 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
  101. landscapeUnit: 'vw', // 横屏时使用的单位
  102. landscapeWidth: 1125 // 横屏时使用的视口宽度
  103. })
  104. ]
  105. }
  106. }
  107. })