vite.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite'
  2. import { createHtmlPlugin } from 'vite-plugin-html'
  3. import vue from '@vitejs/plugin-vue'
  4. import { resolve } from 'path'
  5. import path from 'path'
  6. // import eslintPlugin from 'vite-plugin-eslint'
  7. import AutoImport from 'unplugin-auto-import/vite'
  8. import Components from 'unplugin-vue-components/vite'
  9. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  10. import { visualizer } from 'rollup-plugin-visualizer' // Bundle 分析
  11. // https://vitejs.dev/config/
  12. export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  13. const env = loadEnv(mode, process.cwd())
  14. return {
  15. resolve: {
  16. alias: {
  17. '~': resolve(__dirname, './'),
  18. '@': resolve(__dirname, './src'),
  19. '@assets': path.resolve(__dirname, './assets/images')
  20. }
  21. },
  22. css: {
  23. preprocessorOptions: {
  24. scss: {
  25. additionalData: '@use "@/styles/index.scss" as *;'
  26. }
  27. }
  28. },
  29. server: {
  30. open: false,//打开浏览器
  31. host: '0.0.0.0',
  32. proxy: {
  33. [env.VITE_APP_BASE_API]: {
  34. target: env.VITE_SERVE,
  35. changeOrigin: true,//需要代理跨域
  36. rewrite: (path) => path.replace(/^\/api/, '')
  37. },
  38. // '/testapi': {
  39. // target: 'https://erptest.baozhida.cn',
  40. // changeOrigin: true
  41. // },
  42. // '/ams': {
  43. // target: 'http://erp.baozhida.cn',
  44. // changeOrigin: true
  45. // }
  46. }
  47. },
  48. plugins: [
  49. vue(),
  50. createHtmlPlugin({
  51. inject: {
  52. data: {
  53. title: env.VITE_BZD_ERP_APP_TITLE
  54. }
  55. }
  56. }),
  57. visualizer(),
  58. // eslintPlugin({
  59. // include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue']
  60. // }),
  61. AutoImport({
  62. resolvers: [ElementPlusResolver()]
  63. }),
  64. Components({
  65. resolvers: [ElementPlusResolver()]
  66. })
  67. ],
  68. // * 打包去除 console.log && debugger
  69. esbuild: {
  70. pure: env.VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : []
  71. },
  72. build: {
  73. // rollupOptions: {
  74. // output: {
  75. // // 打包后文件命名
  76. // assetFileNames: '[hash].[name].[ext]'
  77. // }
  78. // },
  79. // // 图片大小分界线:大于 4kb,图片正常打包。小于 4kb,图片会转化为 base64。
  80. // assetsInlineLimit: 4096, // 4kb
  81. // 打包后名称,默认是 dist
  82. outDir: 'ERP'
  83. // 打包后静态目录名称
  84. // assetsDir: 'static'
  85. }
  86. }
  87. })