DocSpring / craco-antd

A craco plugin to use Ant Design with create-react-app
MIT License
234 stars 49 forks source link

Fix CRA + Less modules test crash #31

Closed maxwowo closed 4 years ago

maxwowo commented 4 years ago

Right now if you use the following config

const path = require('path');

const CracoAntDesignPlugin = require("craco-antd");
const CracoLessPlugin = require('craco-less');

module.exports = {
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          javascriptEnabled: true
        }
      }
    },
    {
      plugin: CracoAntDesignPlugin,
      options: {
        cssLoaderOptions: {
          modules: {
            localIdentName: '[local]_[hash:base64:5]'
          }
        },
        modifyLessRule: function (lessRule, _context) {
          lessRule.test = /\.(module)\.(less)$/;
          lessRule.exclude = /node_modules/;

          return lessRule;
        }
      }
    }
  ]
};

and hit yarn test, the test will fail and crash with the following error message image I did some research and found out that if we replaced "es" with "lib" when configuring the Antd babel plugins, it'd fix the problem. I don't know why that works though :(

ndbroadbent commented 4 years ago

Hello, thanks for the PR! I think this might be fixing the issue by referring to the compiled files in lib, instead of the source files. But I'm not sure if this is the correct solution either, or if it will break someone else's project.

Maybe this should be configurable as an option. If you have some time, would it be possible to add this is a configurable setting (with es as the default), and update the README with some instructions?

Thanks again for the PR! Sorry I can't jump in and contribute more, but I'm always happy to merge a PR with good test coverage and documentation.

ndbroadbent commented 4 years ago

Hello, if you are still interested in contributing, could you please rebase your changes onto the master branch and see if all of the tests are still passing?

maxwowo commented 4 years ago

Yep sure thing, just been a bit busy recently, will do that soon

Durisvk commented 4 years ago

Hey @ndbroadbent , this seems ready, can you merge it please?

ndbroadbent commented 4 years ago

Hello, I've merged the changes and pushed a new version: 1.18.1. Thanks!

AO19 commented 4 years ago

This pull request broke my tests/ project.

I'm using es and not lib. Is there an option to configure this now?!

harunurhan commented 3 years ago

@ndbroadbent this is causing end bundle to include all icons from @ant-design/icons, instead of only used ones.