Created
May 30, 2018 10:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
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
Does this still work in 2020?