Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
craco-less
Advanced tools
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
:
$ yarn add craco-less
# OR
$ npm i -S craco-less
Here is a complete craco.config.js
configuration file that adds Less compilation to create-react-app
:
const CracoLessPlugin = require("craco-less");
module.exports = {
plugins: [{ plugin: CracoLessPlugin }],
};
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)
options.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
:
const CracoLessPlugin = require("craco-less");
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
modifyVars: {
"@primary-color": "#1DA57A",
"@link-color": "#1DA57A",
"@border-radius-base": "2px",
},
javascriptEnabled: true,
},
},
},
},
],
};
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
declare module "*.module.less" {
const classes: { readonly [key: string]: string };
export default classes;
}
You can use modifyLessModuleRule
to configure the file suffix and loaders (css-loader, less-loader ...) for less modules.
For example:
const CracoLessPlugin = require("craco-less");
const { loaderByName } = require("@craco/craco");
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
modifyLessRule(lessRule, context) {
// You have to exclude these file suffixes first,
// if you want to modify the less module's suffix
lessRule.exclude = /\.m\.less$/;
return lessRule;
},
modifyLessModuleRule(lessModuleRule, context) {
// Configure the file suffix
lessModuleRule.test = /\.m\.less$/;
// Configure the generated local ident name.
const cssLoader = lessModuleRule.use.find(loaderByName("css-loader"));
cssLoader.options.modules = {
localIdentName: "[local]_[hash:base64:5]",
};
return lessModuleRule;
},
},
},
],
};
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:
$ yarn install
# OR
$ 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
FAQs
A Less plugin for craco / react-scripts / create-react-app
The npm package craco-less receives a total of 25,507 weekly downloads. As such, craco-less popularity was classified as popular.
We found that craco-less demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.