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.

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