Skip to content

Instantly share code, notes, and snippets.

@rickysullivan
Last active October 24, 2019 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickysullivan/e4b75f9a1f2ef77ba0ac733f9bb7395d to your computer and use it in GitHub Desktop.
Save rickysullivan/e4b75f9a1f2ef77ba0ac733f9bb7395d to your computer and use it in GitHub Desktop.
craco-less
const {
getLoader,
loaderByName,
removeLoaders,
throwUnexpectedConfigError
} = require("@craco/craco");
const CracoLessPlugin = require("craco-less");
const path = require("path");
const overrideWebpackConfig = ({
context,
webpackConfig,
pluginOptions
}) => {
// add alias to theme.config
webpackConfig.resolve.alias["../../theme.config$"] = path.join(context.paths.appSrc, "/semantic-ui/theme.config"); // file-loader:
// theme.config, *.variables and *.overrides files should be excluded
const {
isFound,
match: fileLoaderMatch
} = getLoader(webpackConfig, loaderByName("file-loader"));
if (!isFound) {
throwUnexpectedConfigError({
packageName: "@semantic-ui-react/craco-less",
message: `Can't find "file-loader" in the ${context.env} webpack config!`
});
}
fileLoaderMatch.loader.exclude.push(/theme.config$/);
fileLoaderMatch.loader.exclude.push(/\.variables$/);
fileLoaderMatch.loader.exclude.push(/\.overrides$/); // resolve-url-loader:
// should be removed as it causes bugs
// https://github.com/Semantic-Org/Semantic-UI-React/issues/3761
const {
hasRemovedAny
} = removeLoaders(webpackConfig, loaderByName("resolve-url-loader"));
if (!hasRemovedAny) {
throwUnexpectedConfigError({
packageName: "@semantic-ui-react/craco-less",
message: `Can't find "resolve-url-loader" in the ${context.env} webpack config!`
});
} // less-loader:
// craco-less is reused
return CracoLessPlugin.overrideWebpackConfig({
context,
webpackConfig,
pluginOptions
});
};
module.exports = {
overrideWebpackConfig
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment