Gathering detailed insights and metrics for craco-less
Gathering detailed insights and metrics for craco-less
Gathering detailed insights and metrics for craco-less
Gathering detailed insights and metrics for craco-less
craco-scoped-less
在craco-plugin-scoped-css的基础上添加less格式的支持
craco-less-fix
A Less plugin for craco / react-scripts / create-react-app
craco-less-craco7
A Less plugin for craco / react-scripts / create-react-app
@semantic-ui-react/craco-less
This is a [craco][1] plugin that adds Less support to [create-react-app][2] version >= 2. Designed to be used with [Semantic UI React][3] and adds proper configs for [Semantic UI Less][4].
A Less plugin for craco / react-scripts / create-react-app
npm install craco-less
Typescript
Module System
57
Supply Chain
56.8
Quality
70.7
Maintenance
50
Vulnerability
92.4
License
JavaScript (100%)
Total Downloads
14,616,050
Last Day
2,222
Last Week
40,609
Last Month
166,498
Last Year
2,146,824
MIT License
124 Stars
175 Commits
46 Forks
5 Watchers
7 Branches
18 Contributors
Updated on Jun 20, 2025
Minified
Minified + Gzipped
Latest Version
3.0.1
Package Id
craco-less@3.0.1
Unpacked Size
62.03 kB
Size
9.63 kB
File Count
10
Published on
Jul 11, 2023
Cumulative downloads
Total Downloads
Last Day
13%
2,222
Compared to previous day
Last Week
-7.5%
40,609
Compared to previous week
Last Month
4.9%
166,498
Compared to previous month
Last Year
-31.5%
2,146,824
Compared to previous year
2
2
We rely on your help to keep this project up to date and work with the latest versions of craco
and react-scripts
.
Before you send a PR, please check the following:
yarn test
yarn format
yarn lint
yarn audit
You are also welcome to add your GitHub username to the Contributors section at the bottom of this README. (optional)
Pull requests will be ignored and closed if there is a failing build on Travis CI.
This is a craco plugin that adds Less support to create-react-app version >= 2.
Use react-app-rewired for
create-react-app
version 1.
If you want to use Ant Design with create-react-app
,
you should use the craco-antd
plugin.
craco-antd
includes Less and babel-plugin-import
(to only include the required CSS.) It also makes it easy to customize the theme variables.
craco-less
is tested with:
react-scripts
: ^5.0.1
@craco/craco
: ^7.1.0
First, follow the craco
Installation Instructions to install the craco
package, create a craco.config.js
file, and modify the scripts in your package.json
.
Then install craco-less
:
1$ yarn add craco-less 2 3# OR 4 5$ npm i -S craco-less
Here is a complete craco.config.js
configuration file that adds Less compilation to create-react-app
:
1const CracoLessPlugin = require("craco-less"); 2 3module.exports = { 4 plugins: [{ plugin: CracoLessPlugin }], 5};
You can pass an options
object to configure the loaders and plugins(configure less and less modules at the same time). You can also pass a modifyLessRule
(or modifyLessModuleRule
) callback to have full control over the Less webpack rule.
options.styleLoaderOptions
{}
style-loader
optionsoptions.cssLoaderOptions
{ importLoaders: 2 }
css-loader
optionsoptions.postcssLoaderOptions
{ ident: "postcss", plugins: () => [ ... ] }
postcss-loader
optionsoptions.lessLoaderOptions
{}
less-loader
documentation--source-map
=> sourceMap
options.miniCssExtractPluginOptions
(only used in production)
{}
mini-css-extract-plugin
documentationoptions.modifyLessRule(lessRule, context)
lessRule
:
test
: Regex (default: /\.less$/
)exclude
: Regex (default: /\.module\.less$/
)use
: Array of loaders and options.sideEffects
: Boolean (default: true
)context
:
env
: "development" or "production"paths
: An object with paths, e.g. appBuild
, appPath
, ownNodeModules
options.modifyLessModuleRule(lessModuleRule, context)
lessModuleRule
:
test
: Regex (default: /\.module\.less$/
)use
: Array of loaders and options.context
:
env
: "development" or "production"paths
: An object with paths, e.g. appBuild
, appPath
, ownNodeModules
For example, to configure less-loader
:
1const CracoLessPlugin = require("craco-less"); 2 3module.exports = { 4 plugins: [ 5 { 6 plugin: CracoLessPlugin, 7 options: { 8 lessLoaderOptions: { 9 lessOptions: { 10 modifyVars: { 11 "@primary-color": "#1DA57A", 12 "@link-color": "#1DA57A", 13 "@border-radius-base": "2px", 14 }, 15 javascriptEnabled: true, 16 }, 17 }, 18 }, 19 }, 20 ], 21};
CSS / Less modules are enabled by default, and the default file suffix for less modules is .module.less
.
If your project is using typescript, please append the following code to ./src/react-app-env.d.ts
1declare module "*.module.less" { 2 const classes: { readonly [key: string]: string }; 3 export default classes; 4}
You can use modifyLessModuleRule
to configure the file suffix and loaders (css-loader, less-loader ...) for less modules.
For example:
1const CracoLessPlugin = require("craco-less"); 2const { loaderByName } = require("@craco/craco"); 3 4module.exports = { 5 plugins: [ 6 { 7 plugin: CracoLessPlugin, 8 options: { 9 modifyLessRule(lessRule, context) { 10 // You have to exclude these file suffixes first, 11 // if you want to modify the less module's suffix 12 lessRule.exclude = /\.m\.less$/; 13 return lessRule; 14 }, 15 modifyLessModuleRule(lessModuleRule, context) { 16 // Configure the file suffix 17 lessModuleRule.test = /\.m\.less$/; 18 19 // Configure the generated local ident name. 20 const cssLoader = lessModuleRule.use.find(loaderByName("css-loader")); 21 cssLoader.options.modules = { 22 localIdentName: "[local]_[hash:base64:5]", 23 }; 24 25 return lessModuleRule; 26 }, 27 }, 28 }, 29 ], 30};
There is a known problem with Less and CSS modules regarding relative file paths in url(...)
statements. See this issue for an explanation.
If you need to configure anything else for the webpack build, take a look at the
Configuration Overview section in the craco
README. You can use CracoLessPlugin
while making other changes to babel
and webpack
, etc.
Install dependencies:
1$ yarn install 2 3# OR 4 5$ npm install
Run tests:
$ yarn test
Before submitting a pull request, please check the following:
yarn test
open coverage/lcov-report/index.html
yarn lint
yarn format
formatOnSave
option.yarn update_deps
webpack
dependency is needed to silence some annoying warnings from NPM.
This must always match the version from react-scripts
.npm pack
.npmignore
to exclude any files.npm publish
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 7/18 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
31 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More