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
A Less plugin for craco / react-scripts / create-react-app
npm install craco-less
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
123 Stars
175 Commits
48 Forks
7 Watching
7 Branches
18 Contributors
Updated on 18 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-3.2%
7,854
Compared to previous day
Last week
3.7%
44,300
Compared to previous week
Last month
7.8%
177,578
Compared to previous month
Last year
-31.8%
2,509,844
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 -D craco-less 2 3# OR 4 5$ npm i -D 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 dangerous workflow patterns detected
Reason
no binaries found in the repo
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
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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
22 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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