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.

vite.config.ts 2.0KB

3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. entry: {
  41. index: ["babel-polyfill", "./src/main.ts"],
  42. },
  43. //启动服务配置
  44. server: {
  45. host: '0.0.0.0',
  46. port: 8085,
  47. open: true, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序;
  48. cors: true, // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源
  49. https: false,
  50. proxy: {
  51. '/api': {
  52. target: process.env.VUE_APP_BASE_API,
  53. changeOrigin: true,
  54. rewrite: path => path.replace(/^\/api/, '') //重写
  55. },
  56. '/corporateaccount': {
  57. target: process.env.VUE_APP_BASE_API,
  58. changeOrigin: true,
  59. rewrite: path => path.replace(/^\/api/, '') //重写
  60. },
  61. },
  62. },
  63. // 生产环境打包配置
  64. //去除 console debugger
  65. build: {
  66. terserOptions: {
  67. compress: {
  68. drop_console: true,
  69. drop_debugger: true,
  70. },
  71. },
  72. },
  73. }
  74. })