hjyd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import { defineConfig } from 'vite'
  2. import { resolve } from 'path'
  3. import vue from '@vitejs/plugin-vue'
  4. import autoprefixer from 'autoprefixer'
  5. import postcsspxtoviewport from 'postcss-px-to-viewport'
  6. import { chunkSplitPlugin } from 'vite-plugin-chunk-split'
  7. import viteImagemin from 'vite-plugin-imagemin'
  8. // https://vitejs.dev/config/
  9. export default defineConfig({
  10. resolve: {
  11. alias: {
  12. '@': resolve(__dirname, 'src'),
  13. cpns: resolve(__dirname, 'src/components'),
  14. },
  15. extensions: ['.js', '.json', '.vue'],
  16. },
  17. server: {
  18. host: '0.0.0.0',
  19. },
  20. plugins: [
  21. vue(),
  22. chunkSplitPlugin(),
  23. viteImagemin({
  24. gifsicle: {
  25. optimizationLevel: 7,
  26. interlaced: false,
  27. },
  28. optipng: {
  29. optimizationLevel: 7,
  30. },
  31. mozjpeg: {
  32. quality: 20,
  33. },
  34. pngquant: {
  35. quality: [0.8, 0.9],
  36. speed: 4,
  37. },
  38. svgo: {
  39. plugins: [
  40. {
  41. name: 'removeViewBox',
  42. },
  43. {
  44. name: 'removeEmptyAttrs',
  45. active: false,
  46. },
  47. ],
  48. },
  49. }),
  50. ],
  51. //配置sass
  52. css: {
  53. preprocessorOptions: {
  54. scss: {
  55. additionalData:
  56. '@import "./src/assets/scss/globalVar.scss";@import "./src/assets/scss/globalMixin.scss";',
  57. },
  58. },
  59. postcss: {
  60. plugins: [
  61. autoprefixer({
  62. overrideBrowserslist: [
  63. 'Android 4.1',
  64. 'iOS 7.1',
  65. 'Chrome > 31',
  66. 'ff > 31',
  67. 'ie >= 8',
  68. ],
  69. }),
  70. postcsspxtoviewport({
  71. unitToConvert: 'px', // 要转化的单位
  72. viewportWidth: 1920, // UI设计稿的宽度
  73. viewportHeight: 1080, // UI设计稿高度
  74. unitPrecision: 6, // 转换后的精度,即小数点位数
  75. propList: ['*'], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
  76. viewportUnit: 'vw', // 指定需要转换成的视窗单位,默认vw
  77. fontViewportUnit: 'vw', // 指定字体需要转换成的视窗单位,默认vw
  78. selectorBlackList: ['ignore-'], // 指定不转换为视窗单位的类名,
  79. minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
  80. mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
  81. replace: true, // 是否转换后直接更换属性值
  82. // exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
  83. exclude: [],
  84. landscape: false, // 是否处理横屏情况
  85. }),
  86. ],
  87. },
  88. },
  89. })