Skip to content

Instantly share code, notes, and snippets.

@mohandere
Created May 30, 2018 10:51
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 mohandere/60dba8fce5a9d0fc8ebc28bb0e680bca to your computer and use it in GitHub Desktop.
Save mohandere/60dba8fce5a9d0fc8ebc28bb0e680bca to your computer and use it in GitHub Desktop.
config-overrides.js - Obfuscate CSS class names in Create React App without eject
// File - src/config-overrides.js
// react-app-rewired: Override create-react-app webpack configs without ejecting
const path = require("path");
const { compose, getLoader, injectBabelPlugin } = require("react-app-rewired");
function rewire(config, env) {
const cssRules = getLoader(
config.module.rules,
rule => rule.test && String(rule.test) === String(/\.css$/),
);
const cssLoader = getLoader(
env === "production" ? cssRules.loader : config.module.rules,
rule =>
rule.loader &&
rule.loader.indexOf(`${path.sep}css-loader${path.sep}`) !== -1,
);
cssLoader.options = {
...cssLoader.options,
modules: true,
localIdentName: `${env === "production" ? "" : "[local]__"}[hash:base64:8]`,
};
return config;
}
module.exports = rewire;
@Aditya94A
Copy link

Does this still work in 2020?

@Harshmakadia
Copy link

This seems not to be working right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment