You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import legacy from '@vitejs/plugin-legacy'
  7. // https://vitejs.dev/config/
  8. export default defineConfig(({ command, mode }) => {
  9. //https://blog.csdn.net/huanglgln/article/details/121635053 vite获取.env.development配置环境
  10. // 使用 import.meta.env.VITE_APP_BASE_URL
  11. loadEnv(mode, process.cwd())
  12. return {
  13. base: './', //打包路径
  14. plugins: [
  15. legacy({
  16. // targets: ['defaults'], // 需要兼容的目标列表,可以设置多个 , 'not IE 11'
  17. // additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件
  18. }),
  19. vue(),
  20. // gzip压缩 生产环境生成 .gz 文件
  21. viteCompression({
  22. verbose: true,
  23. disable: false,
  24. threshold: 10240,
  25. algorithm: 'gzip',
  26. ext: '.gz',
  27. }),
  28. ],
  29. // 配置别名
  30. resolve: {
  31. alias: {
  32. '@': path.resolve(__dirname, 'src'),
  33. '/icon': './src/assets/ioc', //图片路径别名
  34. },
  35. },
  36. define: {
  37. //定义 process
  38. 'process.env': process.env,
  39. },
  40. css: {
  41. preprocessorOptions: {
  42. scss: {
  43. //引入全局样式
  44. additionalData: '@import "@/assets/style/mian.scss";',
  45. },
  46. },
  47. },
  48. entry: {
  49. index: ['babel-polyfill', './src/main.ts'],
  50. },
  51. //启动服务配置
  52. server: {
  53. host: '0.0.0.0',
  54. port: 8085,
  55. open: true, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
  56. cors: true, // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源
  57. // https: false,
  58. proxy: {
  59. '/common': {
  60. target: 'https://medusa.etcjz.cn',//这里填入你要请求的接口的前缀
  61. changeOrigin: true,//虚拟的站点需要更管origin
  62. ws: true,
  63. secure: true,//是否https接口
  64. pathRewrite: {
  65. '^/common': ''//请求的时候使用这个api就可以
  66. },
  67. // rewrite: (path) => path.replace(/^\/common/, ''), //重写
  68. },
  69. //跨域代理
  70. '/api': {
  71. target: process.env.VUE_APP_BASE_API,
  72. changeOrigin: true,
  73. rewrite: (path) => path.replace(/^\/api/, ''), //重写
  74. },
  75. '/corporateaccount': {
  76. target: process.env.VUE_APP_BASE_API,
  77. changeOrigin: true,
  78. rewrite: (path) => path.replace(/^\/api/, ''), //重写
  79. },
  80. },
  81. },
  82. // 生产环境打包配置
  83. //去除 console debugger
  84. build: {
  85. // target: ['chrome52'],
  86. // cssTarget: ["chrome52"],
  87. minify: 'terser',
  88. terserOptions: {
  89. compress: {
  90. //生产环境移除 console
  91. drop_console: true,
  92. drop_debugger: true,
  93. },
  94. },
  95. },
  96. }
  97. })