'use strict'
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

const name = process.env.VUE_APP_TITLE || '云联私域管理系统' // 网页标题

const port = process.env.port || process.env.npm_config_port || 80 // 端口

// vue.config.js 配置说明
//官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
// 这里只列一部分，具体配置参考文档
module.exports = {
  // 部署生产环境和开发环境下的URL。
  // 默认情况下，Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  // 例如 https://www.test.vip/。如果应用被部署在一个子路径上，你就需要用这个选项指定这个子路径。例如，如果你的应用被部署在 https://www.test.vip/admin/，则设置 baseUrl 为 /admin/。
  publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  // 在npm run build 或 yarn build 时 ，生成文件的目录名称（要和baseUrl的生产环境路径一致）（默认dist）
  outputDir: 'dist',
  // 用于放置生成的静态资源 (js、css、img、fonts) 的；（项目打包之后，静态资源会放在这个文件夹下）
  assetsDir: 'static',
  // 是否开启eslint保存检测，有效值：ture | false | 'error'
  lintOnSave: process.env.NODE_ENV === 'development',
  // 如果你不需要生产环境的 source map，可以将其设置为 false 以加速生产环境构建。
  productionSourceMap: false,
  // transpileDependencies: true, // 默认情况下 babel-loader 忽略 node_modules 中的所有文件，启用此选项需配置transpileDependencies
  transpileDependencies: [
    /@aws-sdk/,
    /@aws/,
    /@smithy/,
    /@huaweicloud/,
    /vod-js-sdk-v6/
  ],
  // webpack-dev-server 相关配置
  devServer: {
    host: '0.0.0.0',
    port: port,
    open: true,
    disableHostCheck: true,
    proxy: {
      // saasadminui all API → fs-company(8006)
      // system/monitor/admin/tool/fs controllers are now enabled in fs-company via @Profile({"admin","company"})
      [process.env.VUE_APP_BASE_API]: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
      },

      // ===== 前端路径与后端不一致的路径重写 → fs-company(8006) =====
      //
      // saasadminui 前端 API 路径与 fs-company 后端控制器路径存在以下不一致：
      // 1. /store/store/* → 后端是 /store/* （前端多了一层 store）
      // 2. /store/his/* → 后端是 /his/* （前端 store/his 实际是 his）
      // 3. /his/fsXxx → 后端是 /store/xxx （his/fs 前缀映射到 store）
      // 4. /his_store/* → 后端是 /hisStore/* （下划线 vs 驼峰）
      // 5. /admin/medical/* → 路由到 fs-admin(8003)
      // 6. /fast_gpt/* → 后端是 /fastGpt/*
      // 7. /wx/wxSop* → 后端是 /qwSop/sopUserLogs*
      // 8. /wxSop/sopUserLogsWx → 后端是 /qwSop/sopUserLogs
      // 9. /sop/companySopRole → 后端是 /companySopRole
      //

      // === 批量路径重写：/store/store/* → /store/* ===
      [process.env.VUE_APP_BASE_API + '/store/store']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/store']: '/store' }
      },
      // === 批量路径重写：/store/his/* → /his/* ===
      [process.env.VUE_APP_BASE_API + '/store/his']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/his']: '/his' }
      },
      // === 批量路径重写：/store/doctor/* → /his/doctor/* ===
      [process.env.VUE_APP_BASE_API + '/store/doctor']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/doctor']: '/his/doctor' }
      },
      // === 批量路径重写：/store/healthTongue/* → /his/healthTongue/* ===
      [process.env.VUE_APP_BASE_API + '/store/healthTongue']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/healthTongue']: '/his/healthTongue' }
      },
      // === 批量路径重写：/store/inquiryOrder/* → /his/inquiryOrder/* ===
      [process.env.VUE_APP_BASE_API + '/store/inquiryOrder']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/inquiryOrder']: '/his/inquiryOrder' }
      },
      // === 批量路径重写：/store/prescribeDrug/* → /his/prescribeDrug/* ===
      [process.env.VUE_APP_BASE_API + '/store/prescribeDrug']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/prescribeDrug']: '/his/prescribeDrug' }
      },
      // === 批量路径重写：/store/healthStoreOrder/* → /hisStore/fsStoreOrderScrm/* ===
      [process.env.VUE_APP_BASE_API + '/store/healthStoreOrder']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/healthStoreOrder']: '/hisStore/fsStoreOrderScrm' }
      },
      // === 批量路径重写：/store/operlogScrm/* → /hisStore/operlogScrm/* ===
      [process.env.VUE_APP_BASE_API + '/store/operlogScrm']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/operlogScrm']: '/hisStore/operlogScrm' }
      },
      // === 批量路径重写：/store/storeOrderOffline/* → /hisStore/fsStoreOrderOfflineScrm/* ===
      [process.env.VUE_APP_BASE_API + '/store/storeOrderOffline']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/storeOrderOffline']: '/hisStore/fsStoreOrderOfflineScrm' }
      },
      // === 批量路径重写：/store/storeOrderAudit/* → /hisStore/fsStoreOrderAuditScrm/* ===
      [process.env.VUE_APP_BASE_API + '/store/storeOrderAudit']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/storeOrderAudit']: '/hisStore/fsStoreOrderAuditScrm' }
      },
      // === 批量路径重写：/store/recommend/* → /store/storeRecommend/* ===
      [process.env.VUE_APP_BASE_API + '/store/recommend']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/recommend']: '/store/storeRecommend' }
      },
      // === 批量路径重写：/store/storeActivity/* → /hisStore/fsStoreActivityScrm/* ===
      [process.env.VUE_APP_BASE_API + '/store/storeActivity']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/storeActivity']: '/hisStore/fsStoreActivityScrm' }
      },
      // === 批量路径重写：/store/collectionSchedule/* → /hisStore/fsCollectionScheduleScrm/* ===
      [process.env.VUE_APP_BASE_API + '/store/collectionSchedule']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/store/collectionSchedule']: '/hisStore/fsCollectionScheduleScrm' }
      },
      // === his_store/* → hisStore/* (下划线转驼峰) ===
      [process.env.VUE_APP_BASE_API + '/his_store']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his_store']: '/hisStore' }
      },
      // === /admin/medical/* → fs-admin(8003) ===
      [process.env.VUE_APP_BASE_API + '/admin/medical']: {
        target: 'http://localhost:8003',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/admin/medical']: '/admin/medical' }
      },
      // === /fast_gpt/* → /fastGpt/* ===
      [process.env.VUE_APP_BASE_API + '/fast_gpt']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/fast_gpt']: '/fastGpt' }
      },
      // === /wxSop/sopUserLogsWx → /qwSop/sopUserLogs ===
      [process.env.VUE_APP_BASE_API + '/wxSop/sopUserLogsWx']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/wxSop/sopUserLogsWx']: '/qwSop/sopUserLogs' }
      },
      // === /sop/companySopRole → /companySopRole ===
      [process.env.VUE_APP_BASE_API + '/sop/companySopRole']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/sop/companySopRole']: '/companySopRole' }
      },
      // === /company/company → /company (前端多了个company前缀) ===
      [process.env.VUE_APP_BASE_API + '/company/company']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/company']: '/company' }
      },
      // === /company/companyConfig → /companyConfig ===
      [process.env.VUE_APP_BASE_API + '/company/companyConfig']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyConfig']: '/companyConfig' }
      },
      // === /company/companyOperLog → /companyOperLog ===
      [process.env.VUE_APP_BASE_API + '/company/companyOperLog']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyOperLog']: '/companyOperLog' }
      },
      // === /company/companyTagGroup → /companyTagGroup ===
      [process.env.VUE_APP_BASE_API + '/company/companyTagGroup']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyTagGroup']: '/companyTagGroup' }
      },
      // === /company/companyTag → /companyTag ===
      [process.env.VUE_APP_BASE_API + '/company/companyTag']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyTag']: '/companyTag' }
      },
      // === /company/companyUser → /companyUser ===
      [process.env.VUE_APP_BASE_API + '/company/companyUser']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyUser']: '/companyUser' }
      },
      // === /company/companyVoice* → /companyVoice* ===
      [process.env.VUE_APP_BASE_API + '/company/companyVoice']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyVoice']: '/companyVoice' }
      },
      // === /company/companyMenu → /companyMenu ===
      [process.env.VUE_APP_BASE_API + '/company/companyMenu']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyMenu']: '/companyMenu' }
      },
      // === /company/companyMoneyLogs → /companyMoneyLogs ===
      [process.env.VUE_APP_BASE_API + '/company/companyMoneyLogs']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyMoneyLogs']: '/companyMoneyLogs' }
      },
      // === /company/companySmsPackage → /companySmsPackage ===
      [process.env.VUE_APP_BASE_API + '/company/companySmsPackage']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companySmsPackage']: '/companySmsPackage' }
      },
      // === /company/redPackage → /redPackage ===
      [process.env.VUE_APP_BASE_API + '/company/redPackage']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/redPackage']: '/redPackage' }
      },
      // === /company/schedule → /schedule ===
      [process.env.VUE_APP_BASE_API + '/company/schedule']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/schedule']: '/schedule' }
      },
      // === /company/addwx → /addwx ===
      [process.env.VUE_APP_BASE_API + '/company/addwx']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/addwx']: '/addwx' }
      },
      // === /company/callphone → /callphone ===
      [process.env.VUE_APP_BASE_API + '/company/callphone']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/callphone']: '/callphone' }
      },
      // === /company/sendmsg → /sendmsg ===
      [process.env.VUE_APP_BASE_API + '/company/sendmsg']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/sendmsg']: '/sendmsg' }
      },
      // === /company/easyCall → /easyCall ===
      [process.env.VUE_APP_BASE_API + '/company/easyCall']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/easyCall']: '/easyCall' }
      },
      // === /company/companyWorkflow → /companyWorkflow ===
      [process.env.VUE_APP_BASE_API + '/company/companyWorkflow']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/companyWorkflow']: '/companyWorkflow' }
      },
      // === /company/module-consumption → /moduleConsumption ===
      [process.env.VUE_APP_BASE_API + '/company/module-consumption']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/module-consumption']: '/moduleConsumption' }
      },
      // === /company/wxUser* → /wxUser* ===
      [process.env.VUE_APP_BASE_API + '/company/wxUser']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/company/wxUser']: '/wxUser' }
      },
      // === /qw/qwInformation → /qw/information ===
      [process.env.VUE_APP_BASE_API + '/qw/qwInformation']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/qw/qwInformation']: '/qw/information' }
      },
      // === /qw/qwAppContactWayLogs → /qw/appContactWayLogs ===
      [process.env.VUE_APP_BASE_API + '/qw/qwAppContactWayLogs']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/qw/qwAppContactWayLogs']: '/qw/appContactWayLogs' }
      },
      // === /qw/qwPushCount → /qw/pushCount ===
      [process.env.VUE_APP_BASE_API + '/qw/qwPushCount']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/qw/qwPushCount']: '/qw/pushCount' }
      },
      // === /qw/records → /qw/record ===
      [process.env.VUE_APP_BASE_API + '/qw/records']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/qw/records']: '/qw/record' }
      },
      // === /qw/workLinkUser → /qw/workLink ===
      [process.env.VUE_APP_BASE_API + '/qw/workLinkUser']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/qw/workLinkUser']: '/qw/workLink' }
      },
      // === /qw/workUser → /qw/work ===
      [process.env.VUE_APP_BASE_API + '/qw/workUser']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/qw/workUser']: '/qw/work' }
      },
      // === /qw/analyze → /qw/analyze (直接透传) ===
      // === /qw/customerProperty → /qw/customerProperty (直接透传) ===
      // === /crm/assist → /crm/assist (直接透传) ===
      // === /crm/analyze → /crm/analyze (直接透传) ===
      // === /crm/third → /crm/third (直接透传) ===
      // === /crm/event → /crm/event (直接透传) ===
      // === /crm/report → /crm/report (直接透传) ===
      // === /crm/customerHisOrder → /crm/customerHisOrder (直接透传) ===
      // === /crm/msg → /crm/msg (直接透传) ===
      // === /his/aiWorkflow → /his/aiWorkflow (直接透传) ===

      // his/fsXxx → store/xxx（saasadminui 用 his/fs 前缀，后端用 store）
      [process.env.VUE_APP_BASE_API + '/his/fsStoreOrder']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreOrder']: '/store/storeOrder' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsInquiryOrderReport']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsInquiryOrderReport']: '/store/inquiryOrderReport' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsInquiryOrder']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsInquiryOrder']: '/store/inquiryOrder' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsDrugReportCount']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsDrugReportCount']: '/store/drugReportCount' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsDrugReport']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsDrugReport']: '/store/drugReport' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsHealthData']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsHealthData']: '/store/healthData' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsHealthRecord']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsHealthRecord']: '/store/healthRecord' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsUserOnlineState']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsUserOnlineState']: '/store/userOnlineState' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsUserCoupon']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsUserCoupon']: '/store/userCoupon' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsUserAddress']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsUserAddress']: '/store/userAddress' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsUser']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsUser']: '/store/user' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsMaterialGroup']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsMaterialGroup']: '/store/materialGroup' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsMaterial']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsMaterial']: '/store/material' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsExportTask']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsExportTask']: '/store/exportTask' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsCoupon']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsCoupon']: '/store/coupon' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsPatient']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsPatient']: '/store/patient' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsPackage']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsPackage']: '/store/package' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreProductCategory']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreProductCategory']: '/store/storeProductCategory' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreProduct']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreProduct']: '/store/storeProduct' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreAfterSales']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreAfterSales']: '/store/storeAfterSales' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsPayment']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsPayment']: '/store/storePayment' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreOrderOffline']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreOrderOffline']: '/hisStore/fsStoreOrderOfflineScrm' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreOrderAudit']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreOrderAudit']: '/hisStore/fsStoreOrderAuditScrm' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreOrderBillLog']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreOrderBillLog']: '/bill/billLog' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsStoreStatistics']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsStoreStatistics']: '/hisStore/fsStoreStatisticsScrm' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsIcd']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsIcd']: '/store/icd' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsPrescribe']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsPrescribe']: '/store/prescribe' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsFollowTemp']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsFollowTemp']: '/store/followTemp' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsCollectionSchedule']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsCollectionSchedule']: '/store/collectionSchedule' }
      },
      [process.env.VUE_APP_BASE_API + '/his/fsCollection']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsCollection']: '/store/collection' }
      },
      // his/fsFirstDiagnosis → his/diagnosis
      [process.env.VUE_APP_BASE_API + '/his/fsFirstDiagnosis']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/his/fsFirstDiagnosis']: '/his/diagnosis' }
      },
      // hisStore/collection → store/collection
      [process.env.VUE_APP_BASE_API + '/hisStore/collection']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/hisStore/collection']: '/store/collection' }
      },
      // wx/wxSop* → qwSop/sopUserLogs* （企微SOP）
      [process.env.VUE_APP_BASE_API + '/wx/wxSopUserInfo']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/wx/wxSopUserInfo']: '/qwSop/sopUserLogsInfo' }
      },
      [process.env.VUE_APP_BASE_API + '/wx/wxSopUser']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/wx/wxSopUser']: '/qwSop/sopUserLogs' }
      },
      [process.env.VUE_APP_BASE_API + '/wx/wxSopLogs']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/wx/wxSopLogs']: '/qwSop/sopUserLogsInfo' }
      },
      [process.env.VUE_APP_BASE_API + '/wx/wxSop']: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/wx/wxSop']: '/qwSop/sopUserLogs' }
      },
      // === /live/coupon → /live/coupon (直接透传，后端已有) ===
      // === /live/liveLotteryProductConf → /live/liveLotteryProductConf (直接透传) ===
      // === /live/liveAfterSalesLogs → /live/liveAfterSalesLogs (直接透传) ===
      // === /live/liveEventConf → /live/liveEventConf (直接透传) ===
      // === /live/liveOrderStatus → /live/liveOrderStatus (直接透传) ===
      // === /live/liveUserRedRecord → /live/liveUserRedRecord (直接透传) ===
      // === /live/trafficLog → /live/trafficLog (直接透传) ===
      // === /live/comment → /live/comment (直接透传) ===
      // === /course/userVideoComment → /course/userVideoComment (直接透传) ===
      // === /course/userCourseComment → /course/userCourseComment (直接透传) ===
      // === /course/userCourseNote → /course/userCourseNote (直接透传) ===
      // === /course/userCourseStudy → /course/userCourseStudy (直接透传) ===
      // === /course/userTalent → /course/userTalent (直接透传) ===
      // === /course/statistics → /course/statistics (直接透传) ===
      // === /course/courseQuestionCategory → /course/courseQuestionCategory (直接透传) ===
      // === /course/fsCourseProduct → /course/fsCourseProduct (直接透传) ===
      // === /course/fsUserCoursePeriodDays → /course/fsUserCoursePeriodDays (直接透传) ===
      // === /course/courseWatchComment → /course/courseWatchComment (直接透传) ===
      // === /course/videoTags → /course/videoTags (直接透传) ===
      // === /course/videoResource → /course/videoResource (直接透传) ===
      // === /his/patient → /his/patient (直接透传) ===
      // === /his/store → /his/store (直接透传) ===
      // === /his/coupon → /his/coupon (直接透传) ===
      // === /his/doctorBill → /his/doctorBill (直接透传) ===
      // === /his/storeBill → /his/storeBill (直接透传) ===
      // === /his/storeLog → /his/storeLog (直接透传) ===
      // === /his/storeExtract → /his/storeExtract (直接透传) ===
      // === /his/storeSubOrder → /his/storeSubOrder (直接透传) ===
      // === /his/storeAfterSales → /his/storeAfterSales (直接透传) ===
      // === /his/storeProduct → /his/storeProduct (直接透传) ===
      // === /his/storeProductPackage → /his/storeProductPackage (直接透传) ===
      // === /his/storeActivity → /his/storeActivity (直接透传) ===
      // === /his/storeOrder → /his/storeOrder (直接透传) ===
      // === /his/user → /his/user (直接透传) ===
      // === /his/userBill → /his/userBill (直接透传) ===
      // === /his/userExtract → /his/userExtract (直接透传) ===
      // === /his/userRecharge → /his/userRecharge (直接透传) ===
      // === /his/userIntegralLogs → /his/userIntegralLogs (直接透传) ===
      // === /his/companyRecharge → /his/companyRecharge (直接透传) ===
      // === /his/companyDeduct → /his/companyDeduct (直接透传) ===
      // === /his/company → /his/company (直接透传) ===
      // === /his/doctorExtract → /his/doctorExtract (直接透传) ===
      // === /his/doctorArticle → /his/doctorArticle (直接透传) ===
      // === /his/doctorArticleCate → /his/doctorArticleCate (直接透传) ===
      // === /his/doctorOperLog → /his/doctorOperLog (直接透传) ===
      // === /his/doctorPrescribeDrug → /his/doctorPrescribeDrug (直接透传) ===
      // === /his/doctorPrescribe → /his/doctorPrescribe (直接透传) ===
      // === /his/doctorProduct → /his/doctorProduct (直接透传) ===
      // === /his/disease → /his/disease (直接透传) ===
      // === /his/illnessLibrary → /his/illnessLibrary (直接透传) ===
      // === /his/inquiryDisease → /his/inquiryDisease (直接透传) ===
      // === /his/inquiryOrderPing → /his/inquiryOrderPing (直接透传) ===
      // === /his/inquiryTemp → /his/inquiryTemp (直接透传) ===
      // === /his/hospital → /his/hospital (直接透传) ===
      // === /his/department → /his/department (直接透传) ===
      // === /his/vessel → /his/vessel (直接透传) ===
      // === /his/chineseMedicine → /his/chineseMedicine (直接透传) ===
      // === /his/famousPrescribe → /his/famousPrescribe (直接透传) ===
      // === /his/medicatedFood → /his/medicatedFood (直接透传) ===
      // === /his/healthLife → /his/healthLife (直接透传) ===
      // === /his/healthHistoryTemp → /his/healthHistoryTemp (直接透传) ===
      // === /his/physicalReportTemplate → /his/physicalReportTemplate (直接透传) ===
      // === /his/physicalReportTemplateField → /his/physicalReportTemplateField (直接透传) ===
      // === /his/testReport → /his/testReport (直接透传) ===
      // === /his/testTemp → /his/testTemp (直接透传) ===
      // === /his/testTempItem → /his/testTempItem (直接透传) ===
      // === /his/template → /his/template (直接透传) ===
      // === /his/questions → /his/questions (直接透传) ===
      // === /his/answer → /his/answer (直接透传) ===
      // === /his/packageCate → /his/packageCate (直接透传) ===
      // === /his/packageSolarTerm → /his/packageSolarTerm (直接透传) ===
      // === /his/packageFavorite → /his/packageFavorite (直接透传) ===
      // === /his/packageOrder → /his/packageOrder (直接透传) ===
      // === /his/dfAccount → /his/dfAccount (直接透传) ===
      // === /his/hfpayConfig → /his/hfpayConfig (直接透传) ===
      // === /his/doctorAdvice → /his/doctorAdvice (直接透传) ===
      // === /his/homeView → /his/homeView (直接透传) ===
      // === /his/homeArticle → /his/homeArticle (直接透传) ===
      // === /his/homeCategory → /his/homeCategory (直接透传) ===
      // === /his/articleCate → /his/articleCate (直接透传) ===
      // === /his/articleViews → /his/articleViews (直接透传) ===
      // === /his/caseArticle → /his/caseArticle (直接透传) ===
      // === /his/adv → /his/adv (直接透传) ===
      // === /his/price → /his/price (直接透传) ===
      // === /his/appVersion → /his/appVersion (直接透传) ===
      // === /his/express → /his/express (直接透传) ===
      // === /his/userAddress → /his/userAddress (直接透传) ===
      // === /his/userCoupon → /his/userCoupon (直接透传) ===
      // === /his/merchantAppConfig → /his/merchantAppConfig (直接透传) ===
      // === /his/pharmacist → /his/pharmacist (直接透传) ===
      // === /his/complaint → /his/complaint (直接透传) ===
      // === /his/healthArticle → /his/healthArticle (直接透传) ===
      // === /his/promotionActive → /his/promotionActive (直接透传) ===
      // === /his/promotionActiveLog → /his/promotionActiveLog (直接透传) ===
      // === /his/logs → /his/logs (直接透传) ===
      // === /his/userNewTask → /his/userNewTask (直接透传) ===
      // === /his/divItem → /his/divItem (直接透传) ===
      // === /his/icd → /his/icd (直接透传) ===
      // === /his/aiWorkflow → /his/aiWorkflow (直接透传) ===
      // === /his/healthData → /his/healthData (直接透传) ===
      // === /his/inquiryOrder → /his/inquiryOrder (直接透传) ===
      // === /his/drugReportCount → /his/drugReportCount (直接透传) ===
      // === /his/doctor → /his/doctor (直接透传) ===
      // === /his/prescription → /his/prescription (直接透传) ===
      // === /his/drugReport → /his/drugReport (直接透传) ===
      // === /his/exportTask → /his/exportTask (直接透传) ===
      // === /his/healthTongue → /his/healthTongue (直接透传) ===
      // === /his/healthRecord → /his/healthRecord (直接透传) ===
      // === /his/diagnosis → /his/diagnosis (直接透传) ===
      // === /his/healthRecordTemplate → /his/healthRecordTemplate (直接透传) ===
      // === /his/healthTongueQuestion → /his/healthTongueQuestion (直接透传) ===
      // === /his/followPlan → /his/followPlan (直接透传) ===
      // === /his/recoveryRecord → /his/recoveryRecord (直接透传) ===
      // === /his/recoveryPlan → /his/recoveryPlan (直接透传) ===
      // === /his/healthReport → /his/healthReport (直接透传) ===
      // === /his/inquiryOrderReport → /his/inquiryOrderReport (直接透传) ===
      // === /his/inquiryDisease → /his/inquiryDisease (直接透传) ===
      // === /his/integralGoods → /his/integralGoods (直接透传) ===
      // === /his/integralOrder → /his/integralOrder (直接透传) ===
      // === /his/redPacket → /his/redPacket (直接透传) ===

      // watch-api → fs-watch 微服务（需要单独启动 fs-watch）
      [process.env.VUE_APP_BASE_API + '/watch-api']: {
        target: 'http://localhost:8010',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API + '/watch-api']: '' }
      },

      // ===== 默认所有其他请求 → fs-company(8006) 租户服务端 =====
      [process.env.VUE_APP_BASE_API]: {
        target: 'http://localhost:8006',
        changeOrigin: true,
        pathRewrite: { ['^' + process.env.VUE_APP_BASE_API]: '' }
      }
    }
  },
  configureWebpack: {
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    externals: {
      'node:async_hooks': 'commonjs async_hooks',
      'node:crypto': 'commonjs crypto',
      'node:fs': 'commonjs fs',
      'node:fs/promises': 'commonjs fs/promises',
      'node:http': 'commonjs http',
      'node:os': 'commonjs os',
      'node:path': 'commonjs path',
      'node:process': 'commonjs process',
      'node:stream': 'commonjs stream',
      'node:stream/web': 'commonjs stream',
      'node:buffer': 'commonjs buffer',
      'node:util': 'commonjs util',
      'node:url': 'commonjs url',
      'node:net': 'commonjs net',
      'node:tls': 'commonjs tls',
      'node:events': 'commonjs events',
      'node:https': 'commonjs https',
      'node:zlib': 'commonjs zlib',
      'node:child_process': 'commonjs child_process'
    }
  },
  chainWebpack(config) {
    config.plugins.delete('preload') // TODO: need test
    config.plugins.delete('prefetch') // TODO: need test

    // set svg-sprite-loader
    config.module
      .rule('svg')
      .exclude.add(resolve('src/assets/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()

    config
      .when(process.env.NODE_ENV !== 'development',
        config => {
          config
            .plugin('ScriptExtHtmlWebpackPlugin')
            .after('html')
            .use('script-ext-html-webpack-plugin', [{
            // `runtime` must same as runtimeChunk name. default is `runtime`
              inline: /runtime\..*\.js$/
            }])
            .end()
          config
            .optimization.splitChunks({
              chunks: 'all',
              cacheGroups: {
                libs: {
                  name: 'chunk-libs',
                  test: /[\\/]node_modules[\\/]/,
                  priority: 10,
                  chunks: 'initial' // only package third parties that are initially dependent
                },
                elementUI: {
                  name: 'chunk-elementUI', // split elementUI into a single package
                  priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                  test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                },
                commons: {
                  name: 'chunk-commons',
                  test: resolve('src/components'), // can customize your rules
                  minChunks: 3, //  minimum common number
                  priority: 5,
                  reuseExistingChunk: true
                }
              }
            })
          config.optimization.runtimeChunk('single'),
          {
             from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
             to: './' //到根目录下
          }
        }
      )
  }
}
