Skip to content
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

Allow custom includePaths for sass #5599

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/react-scripts/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dotenvFiles.forEach(dotenvFile => {
}
});

const appDirectory = fs.realpathSync(process.cwd());

// We support resolving modules according to `NODE_PATH`.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebook/create-react-app/issues/253.
Expand All @@ -57,13 +59,18 @@ dotenvFiles.forEach(dotenvFile => {
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
// We also resolve them to make sure all tools using them work consistently.
const appDirectory = fs.realpathSync(process.cwd());
process.env.NODE_PATH = (process.env.NODE_PATH || '')
.split(path.delimiter)
.filter(folder => folder && !path.isAbsolute(folder))
.map(folder => path.resolve(appDirectory, folder))
.join(path.delimiter);

process.env.SASS_INCLUDEPATHS = (process.env.SASS_INCLUDEPATHS || '')
.split(path.delimiter)
.filter(folder => folder)
.map(folder => path.resolve(appDirectory, folder))
.join(path.delimiter);

// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
// injected into the application via DefinePlugin in Webpack configuration.
const REACT_APP = /^REACT_APP_/i;
Expand Down
27 changes: 21 additions & 6 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const getStyleLoaders = (cssOptions, preProcessor) => {
},
];
if (preProcessor) {
loaders.push(require.resolve(preProcessor));
loaders.push(preProcessor);
}
return loaders;
};
Expand Down Expand Up @@ -315,9 +315,7 @@ module.exports = {
{
test: cssRegex,
exclude: cssModuleRegex,
use: getStyleLoaders({
importLoaders: 1,
}),
use: getStyleLoaders({ importLoaders: 1 }),
},
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)
// using the extension .module.css
Expand All @@ -337,7 +335,17 @@ module.exports = {
{
test: sassRegex,
exclude: sassModuleRegex,
use: getStyleLoaders({ importLoaders: 2 }, 'sass-loader'),
use: getStyleLoaders(
{ importLoaders: 2 },
{
loader: require.resolve('sass-loader'),
options: {
includePaths: process.env.SASS_INCLUDEPATHS.split(
path.delimiter
).filter(Boolean),
},
}
),
},
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
Expand All @@ -349,7 +357,14 @@ module.exports = {
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'sass-loader'
{
loader: require.resolve('sass-loader'),
options: {
includePaths: process.env.SASS_INCLUDEPATHS.split(
path.delimiter
).filter(Boolean),
},
}
),
},
// "file" loader makes sure those assets get served by WebpackDevServer.
Expand Down
27 changes: 19 additions & 8 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ const getStyleLoaders = (cssOptions, preProcessor) => {
},
];
if (preProcessor) {
loaders.push({
loader: require.resolve(preProcessor),
options: {
sourceMap: shouldUseSourceMap,
},
});
loaders.push(preProcessor);
}
return loaders;
};
Expand Down Expand Up @@ -422,7 +417,15 @@ module.exports = {
importLoaders: 2,
sourceMap: shouldUseSourceMap,
},
'sass-loader'
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: shouldUseSourceMap,
includePaths: process.env.SASS_INCLUDEPATHS.split(
path.delimiter
).filter(Boolean),
},
}
),
// Don't consider CSS imports dead code even if the
// containing package claims to have no side effects.
Expand All @@ -441,7 +444,15 @@ module.exports = {
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'sass-loader'
{
loader: require.resolve('sass-loader'),
options: {
sourceMap: shouldUseSourceMap,
includePaths: process.env.SASS_INCLUDEPATHS.split(
path.delimiter
).filter(Boolean),
},
}
),
},
// "file" loader makes sure assets end up in the `build` folder.
Expand Down