-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Add support for LESS stylesheets #10494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
89642ef
to
3ad7892
Compare
When testing in manual mode (pull + pack + resolutions) my less files are not built. Any idea why ? |
I found why it didn't work : due to the version being under the current remote version it didn't take the local resolution. |
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. |
Includes also the possibility to pass options to the less loader through en environment variable.
This is much easier to manage than a JSON string. It also allows for using JS, e.g. in options that accept functions.
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? |
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. |
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. |
Hi guys, I would to share a safe solution which it's not based on any dependency like
yarn create react-app
yarn add less less-watch-compiler concurrently -D
{
"watchFolder": "src/",
"outputFolder": "src/",
"sourceMap": true,
"runOnce": false,
"enableJs": true
}
...
"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. |
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. |
@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 |
Thanks @tommie-lie, this looks awesome! |
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. |
Resolves #10336
Changes done has been mainly deduced from the current implementation for SASS support. These include:
react-scripts
with the possibility to pass options toless-loader
through a predefined file in the app root folderreact-dev-utils
Test plan:
node_modules
less
hasn't been installedyarn e2e:docker --test-suite <test suite>
). Tests that are not passing don't seem to be related to this PR.