Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vite.config.ts 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. //@ts-ignore
  5. import viteCompression from 'vite-plugin-compression'
  6. // https://vitejs.dev/config/
  7. export default defineConfig(({ command, mode }) => {
  8. //https://blog.csdn.net/huanglgln/article/details/121635053 vite获取.env.development配置环境
  9. // 使用 import.meta.env.VITE_APP_BASE_URL
  10. loadEnv(mode, process.cwd());
  11. return {
  12. base: './', //打包路径
  13. plugins: [
  14. vue(),
  15. // gzip压缩 生产环境生成 .gz 文件
  16. viteCompression({
  17. verbose: true,
  18. disable: false,
  19. threshold: 10240,
  20. algorithm: 'gzip',
  21. ext: '.gz',
  22. }),
  23. ],
  24. // 配置别名
  25. resolve: {
  26. alias: {
  27. '@': path.resolve(__dirname, 'src'),
  28. },
  29. },
  30. define: { //定义 process
  31. 'process.env': process.env
  32. },
  33. css: {
  34. preprocessorOptions: {
  35. scss: { //引入全局样式
  36. additionalData: '@import "@/assets/style/mian.scss";',
  37. },
  38. },
  39. },
  40. //启动服务配置
  41. server: {
  42. host: '0.0.0.0',
  43. port: 8085,
  44. open: true, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
  45. cors: true, // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源
  46. https: false,
  47. proxy: {
  48. '/api': {
  49. target: process.env.VUE_APP_BASE_API,
  50. changeOrigin: true,
  51. rewrite: path => path.replace(/^\/api/, '') //重写
  52. }
  53. },
  54. },
  55. // 生产环境打包配置
  56. //去除 console debugger
  57. build: {
  58. terserOptions: {
  59. compress: {
  60. drop_console: true,
  61. drop_debugger: true,
  62. },
  63. },
  64. },
  65. }
  66. })