vite.config.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import topLevelAwait from 'vite-plugin-top-level-await'
  4. import { resolve } from 'path'
  5. import viteCompression from 'vite-plugin-compression' //Gzip
  6. import { visualizer } from 'rollup-plugin-visualizer'
  7. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // 【svg-icons相关】
  8. import VitePluginHtmlEnv from 'vite-plugin-html-env'
  9. // @ts-ignore
  10. import tailwindcss from '@tailwindcss/vite'
  11. import { quasar, transformAssetUrls } from '@quasar/vite-plugin'
  12. import postcsspxtoviewport from 'postcss-px-to-viewport'
  13. const time = new Date().getTime()
  14. export default defineConfig(({ mode, command }) => {
  15. const env = loadEnv(mode, process.cwd())
  16. const { VITE_BASE } = env
  17. return {
  18. define: {
  19. 'process.env': process.env,
  20. },
  21. plugins: [
  22. vue({
  23. template: { transformAssetUrls },
  24. }),
  25. quasar(),
  26. tailwindcss(),
  27. viteCompression(),
  28. VitePluginHtmlEnv(),
  29. visualizer(),
  30. createSvgIconsPlugin({
  31. // 指定需要缓存的图标文件夹
  32. iconDirs: [resolve(process.cwd(), 'src/assets/svg')],
  33. // 指定symbolId格式
  34. symbolId: 'icon-[dir]-[name]',
  35. // svgoOptions: {
  36. // plugins: [
  37. // {
  38. // name: 'removeAttrs',
  39. // params: {
  40. // attrs: ['class', 'data-name', 'fill', 'stroke']
  41. // }
  42. // }
  43. // ]
  44. // }
  45. }),
  46. topLevelAwait({
  47. promiseExportName: '__tla',
  48. promiseImportName: (i) => `__tla_${i}`,
  49. }),
  50. ],
  51. base: '/' + VITE_BASE + '/',
  52. resolve: {
  53. alias: {
  54. '@': resolve(__dirname, 'src'),
  55. },
  56. },
  57. // css: {
  58. // postcss: {
  59. // plugins: [
  60. // postcsspxtoviewport({
  61. // unitToConvert: 'px',
  62. // viewportWidth: 1920,
  63. // unitPrecision: 5, // 单位转换后保留的精度
  64. // propList: ['*'], // 能转化为vw的属性列表
  65. // viewportUnit: 'vw', // 希望使用的视口单位
  66. // fontViewportUnit: 'vw', // 字体使用的视口单位
  67. // selectorBlackList: ['ignore-'], // 需要忽略的CSS选择器,不会转为视口单位,使用原有的px等单位。
  68. // minPixelValue: 1, // 设置最小的转换数值,如果为1的话,只有大于1的值会被转换
  69. // mediaQuery: true, // 媒体查询里的单位是否需要转换单位
  70. // replace: true, // 是否直接更换属性值,而不添加备用属性
  71. // exclude: [], // 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
  72. // include: [], // 如果设置了include,那将只有匹配到的文件才会被转换
  73. // landscape: false, // 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)
  74. // landscapeUnit: 'vw', // 横屏时使用的单位
  75. // landscapeWidth: 816, // 横屏时使用的视口宽度
  76. // }),
  77. // ],
  78. // },
  79. // },
  80. server: {
  81. port: 9616,
  82. host: '0.0.0.0',
  83. open: true,
  84. strictPort: false,
  85. proxy: {
  86. [env.VITE_BASE_API_PROXY]: {
  87. // target: 'https://bzx.85coding.com/prod-api/',
  88. target: 'https://bzx.85coding.com:8083/prod-api/',
  89. changeOrigin: true,
  90. rewrite: (path) => path.replace(env.VITE_BASE_API_PROXY, ''),
  91. },
  92. },
  93. },
  94. build: {
  95. cssTarget: 'chrome83', // 将编译的css版本进行chrome83版本适应
  96. outDir: 'study-ipad',
  97. rollupOptions: {
  98. //分包优化
  99. output: {
  100. manualChunks(id) {
  101. if (id.includes('node_modules')) {
  102. return (
  103. time +
  104. id.toString().split('node_modules/')[1].split('/')[0].toString()
  105. )
  106. } else {
  107. return time + id.toString()
  108. }
  109. },
  110. },
  111. },
  112. },
  113. publicDir: 'src/out',
  114. optimizeDeps: {
  115. include: [],
  116. },
  117. } as any
  118. })