vite.config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * @Description:: 打包配置文件
  3. * @Version: V1.0.0
  4. * @Author: 舟舟
  5. * @Date: 2022-06-25 22:48:58
  6. * @LastEditors: 舟舟
  7. * @LastEditTime: 2022-07-30 23:18:53
  8. * @FilePath: /ouicai_web_framework_vite_ep_nolang/vite.config.ts
  9. */
  10. import vue from '@vitejs/plugin-vue'
  11. import { resolve } from 'path'
  12. import type { UserConfig, ConfigEnv } from 'vite'
  13. import { isProd, loadEnv } from '/@/utils/vite'
  14. import { svgBuilder } from '/@/components/icon/svg/index'
  15. import viteCompression from 'vite-plugin-compression'
  16. const pathResolve = (dir: string): any => {
  17. return resolve(__dirname, '.', dir)
  18. }
  19. // https://vitejs.cn/config/
  20. const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
  21. const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR } = loadEnv(mode)
  22. const alias: Record<string, string> = {
  23. '/@': pathResolve('./src/'),
  24. assets: pathResolve('./src/assets')
  25. }
  26. return {
  27. plugins: [vue(), svgBuilder('./src/assets/icons/'),viteCompression({
  28. threshold: 1024000 // 对大于 1mb 的文件进行压缩
  29. })],
  30. root: process.cwd(),
  31. resolve: { alias },
  32. base: VITE_BASE_PATH,
  33. server: {
  34. host: '0.0.0.0',
  35. port: VITE_PORT,
  36. open: VITE_OPEN,
  37. },
  38. build: {
  39. sourcemap: false,
  40. outDir: VITE_OUT_DIR,
  41. emptyOutDir: true,
  42. chunkSizeWarningLimit: 1500,
  43. },
  44. css: {
  45. postcss: {
  46. plugins: [
  47. {
  48. postcssPlugin: 'internal:charset-removal',
  49. AtRule: {
  50. charset: (atRule) => {
  51. if (atRule.name === 'charset') {
  52. atRule.remove()
  53. }
  54. },
  55. },
  56. },
  57. ],
  58. },
  59. }
  60. }
  61. }
  62. export default viteConfig