Skip to content

Conversation

hbj
Copy link

@hbj hbj commented Feb 3, 2021

Resolves #10336

Changes done has been mainly deduced from the current implementation for SASS support. These include:

  • Add opt-in support for LESS and LESS modules to webpack config in react-scripts with the possibility to pass options to less-loader through a predefined file in the app root folder
  • Add documentation
  • Add LESS support utils to react-dev-utils
  • Add tests to kitchensink test suite

Test plan:

  • Manually test the end-to-end flow as described in the contribution document. The following features have been tested:
    • Loading of local LESS stylesheets
    • Loading of LESS stylesheets from node_modules
    • Loading of local LESS modules
    • Generated CSS identifier of LESS modules (for index and non-index files)
    • Helper error message output if less hasn't been installed
  • Added unit tests and made sure they pass by running the corresponding test suites (yarn e2e:docker --test-suite <test suite>). Tests that are not passing don't seem to be related to this PR.

NOTE: The documentation contains a hint that the feature is available with react-scripts@4.1.0 and higher. I included this temporarily as I don't know in which version this would be included, so this has to be updated once the information becomes available.

@hbj hbj force-pushed the add-less-support branch 2 times, most recently from 89642ef to 3ad7892 Compare February 6, 2021 10:04
@SimonChaumet
Copy link

When testing in manual mode (pull + pack + resolutions) my less files are not built. Any idea why ?

@SimonChaumet
Copy link

I found why it didn't work : due to the version being under the current remote version it didn't take the local resolution.

@stale
Copy link

stale bot commented Jun 26, 2021

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jun 26, 2021
@hbj hbj force-pushed the add-less-support branch from a435485 to dc7645f Compare June 28, 2021 10:30
@stale stale bot removed the stale label Jun 28, 2021
@mrmckeb
Copy link
Contributor

mrmckeb commented Jun 30, 2021

Hi @hbj, the team have considered Less support in the past, but with Sass support already included we feel this covers enough use cases.

Was there something particular you needed from Less that you can't get from Sass?

@mxcl
Copy link

mxcl commented Jun 30, 2021

Ant-Design is a very popular React based UI framework, it uses LESS (unfortunately). Currently in my project I use a separate step compiling their LESS templates with my own modifications to make something that can be ingested by CRA.

Thus I have been watching and waiting on this PR.

Anyway, just adding this so you have some data. If you don’t merge I get it, maintenance is a bitch.

@hbj
Copy link
Author

hbj commented Jul 1, 2021

Hi @hbj, the team have considered Less support in the past, but with Sass support already included we feel this covers enough use cases.

Was there something particular you needed from Less that you can't get from Sass?

Hi @mrmckeb, as @mxcl said, Ant Design was the main reason why we need Less support. We use Ant Design in different projects and we integrate it in a way that we have access to the Less variables and that we can customise the theme, but to do it we must always use some tool like 'cra-rewrite' which has its own compatibility issues with the latest versions of CRA.

@3imed-jaberi
Copy link

Hi guys, I would to share a safe solution which it's not based on any dependency like react-app-rewired ..

  1. Use CRA
yarn create react-app 
  1. Add these deps
yarn add less less-watch-compiler concurrently -D
  1. create less-watcher.config.json file then add these config (config-docs)
{
  "watchFolder": "src/",
  "outputFolder": "src/",
  "sourceMap": true,
  "runOnce": false,
  "enableJs": true
}
  1. change the start scritpt in package.json
...
"scripts": {
    "start": "concurrently --kill-others \"less-watch-compiler --config less-watcher.config.json\" \"react-scripts start\"",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
...

This solution was originally provided by @joefstack in his blog post here.

@hbj
Copy link
Author

hbj commented Aug 2, 2021

Thanks @3imed-jaberi for the suggestion. I generally prefer to have all tasks handled directly by react scripts, but this looks interesting and better than trying to mess with the Webpack configuration (e.g. with 'cra-rewrite').

Regarding the npm scripts update, I think you must also add a compilation step of the LESS files before running react scripts for the 'build' and 'test' scripts, otherwise you might find yourself working with outdated CSS files.

@tommie-lie
Copy link

@hbj if you want to have all tasks handled by react-scripts directly (and don't wan't the additional dependency of concurrently and less-watch-compiler) you can try this: https://github.com/tommie-lie/cra-antd-customization#tldr

@hbj
Copy link
Author

hbj commented Aug 3, 2021

Thanks @tommie-lie, this looks awesome!

@stale
Copy link

stale bot commented Jan 9, 2022

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

less-loader
7 participants