config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // https://umijs.org/config/
  2. import os from "os";
  3. import pageRoutes from "./router.config";
  4. import webpackPlugin from "./plugin.config";
  5. import defaultSettings from "../src/defaultSettings";
  6. const isProd = process.env.NODE_ENV === "production";
  7. const plugins = [
  8. [
  9. "umi-plugin-react",
  10. {
  11. antd: true,
  12. dva: {
  13. hmr: !isProd,
  14. },
  15. targets: {
  16. ie: 11,
  17. },
  18. locale: {
  19. enable: true, // default false
  20. default: "zh-CN", // default zh-CN
  21. baseNavigator: false, // default true, when it is true, will use `navigator.language` overwrite default
  22. },
  23. dynamicImport: {
  24. loadingComponent: "./components/PageLoading/index",
  25. },
  26. pwa: {
  27. workboxPluginMode: "InjectManifest",
  28. workboxOptions: {
  29. importWorkboxFrom: "local",
  30. },
  31. },
  32. ...(!process.env.TEST && os.platform() === "darwin"
  33. ? {
  34. dll: {
  35. include: ["dva", "dva/router", "dva/saga", "dva/fetch"],
  36. exclude: ["@babel/runtime"],
  37. },
  38. }
  39. : {}),
  40. },
  41. ],
  42. ];
  43. // 针对 preview.pro.ant.design 的 GA 统计代码
  44. // 业务上不需要这个
  45. if (process.env.APP_TYPE === "site") {
  46. // plugins.push([
  47. // 'umi-plugin-ga',
  48. // {
  49. // code: 'UA-72788897-6',
  50. // },
  51. // ]);
  52. }
  53. export default {
  54. // add for transfer to umi
  55. plugins,
  56. targets: {
  57. ie: 11,
  58. },
  59. define: {
  60. APP_TYPE: process.env.APP_TYPE || "",
  61. },
  62. // 路由配置
  63. routes: pageRoutes,
  64. // Theme for antd
  65. // https://ant.design/docs/react/customize-theme-cn
  66. theme: {
  67. "primary-color": defaultSettings.primaryColor,
  68. },
  69. externals: {
  70. "@antv/data-set": "DataSet",
  71. },
  72. proxy: {
  73. "/api/": {
  74. target: "http://54.46.9.88:8001/",
  75. changeOrigin: true,
  76. pathRewrite: { "^/api": "" },
  77. },
  78. },
  79. ignoreMomentLocale: true,
  80. lessLoaderOptions: {
  81. javascriptEnabled: true,
  82. },
  83. disableRedirectHoist: true,
  84. cssLoaderOptions: {
  85. modules: true,
  86. getLocalIdent: (context, localIdentName, localName) => {
  87. if (
  88. context.resourcePath.includes("node_modules") ||
  89. context.resourcePath.includes("ant.design.pro.less") ||
  90. context.resourcePath.includes("global.less")
  91. ) {
  92. return localName;
  93. }
  94. const match = context.resourcePath.match(/src(.*)/);
  95. if (match && match[1]) {
  96. const antdProPath = match[1].replace(".less", "");
  97. const arr = antdProPath
  98. .split("/")
  99. .map((a) => a.replace(/([A-Z])/g, "-$1"))
  100. .map((a) => a.toLowerCase());
  101. return `antd-pro${arr.join("-")}-${localName}`.replace(/--/g, "-");
  102. // return `${localName}`;
  103. }
  104. return localName;
  105. },
  106. // pluginOptions: {
  107. // "style-resources-loader": {
  108. // preProcessor: "less",
  109. // patterns: [
  110. // // 全局变量路径
  111. // path.resolve(__dirname, "./src/global.less"),
  112. // ],
  113. // },
  114. // }
  115. },
  116. manifest: {
  117. basePath: "/",
  118. },
  119. publicPath: "/",
  120. chainWebpack: webpackPlugin,
  121. // 开发环境关闭 source map 以提升速度
  122. devtool: isProd ? false : "cheap-module-source-map",
  123. };