Skip to content

Commit 7519045

Browse files
authored
Merge pull request #1 from sinecycle/less-config
adds less support to cra
2 parents fd8c5f7 + aed0e3d commit 7519045

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

packages/react-scripts/config/webpack.config.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const cssRegex = /\.css$/;
8181
const cssModuleRegex = /\.module\.css$/;
8282
const sassRegex = /\.(scss|sass)$/;
8383
const sassModuleRegex = /\.module\.(scss|sass)$/;
84+
const lessRegex = /\.less$/;
8485

8586
const hasJsxRuntime = (() => {
8687
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
@@ -115,7 +116,7 @@ module.exports = function (webpackEnv) {
115116
const shouldUseReactRefresh = env.raw.FAST_REFRESH;
116117

117118
// common function to get style loaders
118-
const getStyleLoaders = (cssOptions, preProcessor) => {
119+
const getStyleLoaders = (cssOptions, preProcessor, preProcessorOptions = {}) => {
119120
const loaders = [
120121
isEnvDevelopment && require.resolve('style-loader'),
121122
isEnvProduction && {
@@ -188,6 +189,7 @@ module.exports = function (webpackEnv) {
188189
{
189190
loader: require.resolve(preProcessor),
190191
options: {
192+
...preProcessorOptions,
191193
sourceMap: true,
192194
},
193195
}
@@ -582,6 +584,35 @@ module.exports = function (webpackEnv) {
582584
'sass-loader'
583585
),
584586
},
587+
// Adds support for Less (using .less extensions)
588+
{
589+
test: lessRegex,
590+
use: getStyleLoaders(
591+
{
592+
importLoaders: 3,
593+
sourceMap: isEnvProduction
594+
? shouldUseSourceMap
595+
: isEnvDevelopment,
596+
modules: {
597+
mode: 'icss',
598+
},
599+
},
600+
'less-loader',
601+
{
602+
lessOptions: {
603+
javascriptEnabled: true,
604+
modifyVars: {
605+
'@primary-color': '#722ed1'
606+
},
607+
}
608+
}
609+
),
610+
// Don't consider CSS imports dead code even if the
611+
// containing package claims to have no side effects.
612+
// Remove this when webpack adds a warning or an error for this.
613+
// See https://github.com/webpack/webpack/issues/6571
614+
sideEffects: true,
615+
},
585616
// "file" loader makes sure those assets get served by WebpackDevServer.
586617
// When you `import` an asset, you get its (virtual) filename.
587618
// In production, they would get copied to the `build` folder.

packages/react-scripts/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
2-
"name": "react-scripts",
2+
"name": "@growfin/react-scripts",
33
"version": "5.0.0",
44
"description": "Configuration and scripts for Create React App.",
55
"repository": {
66
"type": "git",
7-
"url": "https://github.com/facebook/create-react-app.git",
7+
"url": "https://github.com/sinecycle/create-react-app.git",
88
"directory": "packages/react-scripts"
99
},
1010
"license": "MIT",
1111
"engines": {
1212
"node": ">=14.0.0"
1313
},
1414
"bugs": {
15-
"url": "https://github.com/facebook/create-react-app/issues"
15+
"url": "https://github.com/sinecycle/create-react-app/issues"
1616
},
1717
"files": [
1818
"bin",
@@ -53,6 +53,8 @@
5353
"jest": "^27.4.3",
5454
"jest-resolve": "^27.4.2",
5555
"jest-watch-typeahead": "^1.0.0",
56+
"less": "^4.1.2",
57+
"less-loader": "^10.2.0",
5658
"mini-css-extract-plugin": "^2.4.5",
5759
"postcss": "^8.4.4",
5860
"postcss-flexbugs-fixes": "^5.0.2",

0 commit comments

Comments
 (0)