config-overrides.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-04-23 15:39:41
  4. * @LastEditTime: 2021-04-29 11:39:28
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /react-antd-admin-template/config-overrides.js
  8. */
  9. const {
  10. override,
  11. fixBabelImports,
  12. addLessLoader,
  13. addWebpackAlias,
  14. } = require("customize-cra");
  15. const path = require("path");
  16. function resolve(dir) {
  17. return path.join(__dirname, dir);
  18. }
  19. process.env.CI = "false";
  20. const addCustomize = () => (config) => {
  21. // if (config.output.publicPath) {
  22. // config.output.publicPath =
  23. // process.env.NODE_ENV === "production"
  24. // ? "/"
  25. // : "/";
  26. // }
  27. if (config.resolve) {
  28. config.resolve.extensions.push(".jsx");
  29. }
  30. return config;
  31. };
  32. module.exports = override(
  33. // 针对antd实现按需打包: 根据import来打包(使用babel-plugin-import)
  34. fixBabelImports("import", {
  35. libraryName: "antd",
  36. libraryDirectory: "es",
  37. style: true, // 自动打包相关的样式
  38. }),
  39. // 使用less-loader对源码中的less的变量进行重新指定
  40. addLessLoader({
  41. javascriptEnabled: true,
  42. modifyVars: { "@primary-color": "#4E78FF" },
  43. }),
  44. // 配置路径别名
  45. addWebpackAlias({
  46. "@": resolve("src"),
  47. }),
  48. addCustomize()
  49. );