vite.config.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. define: {
  23. 'process.env.NODE_ENV': '"production"'
  24. },
  25. css: {
  26. preprocessorOptions: {
  27. scss: {
  28. additionalData: '@use "@/styles/index.scss" as *;'
  29. }
  30. }
  31. },
  32. server: {
  33. open: false,//打开浏览器
  34. host: '0.0.0.0',
  35. proxy: {
  36. [env.VITE_APP_BASE_API]: {
  37. target: env.VITE_SERVE,
  38. changeOrigin: true,//需要代理跨域
  39. rewrite: (path) => path.replace(/^\/api/, '')
  40. },
  41. // '/testapi': {
  42. // target: 'https://erptest.baozhida.cn',
  43. // changeOrigin: true
  44. // },
  45. // '/ams': {
  46. // target: 'http://erp.baozhida.cn',
  47. // changeOrigin: true
  48. // }
  49. }
  50. },
  51. plugins: [
  52. vue(),
  53. createHtmlPlugin({
  54. inject: {
  55. data: {
  56. title: env.VITE_BZD_ERP_APP_TITLE
  57. }
  58. }
  59. }),
  60. visualizer(),
  61. // eslintPlugin({
  62. // include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue']
  63. // }),
  64. AutoImport({
  65. resolvers: [ElementPlusResolver()]
  66. }),
  67. Components({
  68. resolvers: [ElementPlusResolver()]
  69. })
  70. ],
  71. optimizeDeps: {
  72. include: ['element-plus/es/locale/lang/zh-cn'],
  73. },
  74. // * 打包去除 console.log && debugger
  75. esbuild: {
  76. pure: env.VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : []
  77. },
  78. build: {
  79. // rollupOptions: {
  80. // output: {
  81. // // 打包后文件命名
  82. // assetFileNames: '[hash].[name].[ext]'
  83. // }
  84. // },
  85. // // 图片大小分界线:大于 4kb,图片正常打包。小于 4kb,图片会转化为 base64。
  86. // assetsInlineLimit: 4096, // 4kb
  87. // 打包后名称,默认是 dist
  88. outDir: 'ERP'
  89. // 打包后静态目录名称
  90. // assetsDir: 'static'
  91. }
  92. }
  93. })