Skip to content
Open
Changes from 1 commit
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
Next Next commit
feat(react-scripts): Provide way to obfuscate css modules ident names.
  • Loading branch information
zamarawka committed Jun 26, 2020
commit f642660e97d7786bed4d129a19c6a9834e2548df
15 changes: 9 additions & 6 deletions packages/react-scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const appPackageJson = require(paths.appPackageJson);
// Source maps are resource heavy and can cause out of memory issue for large source files.
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';

const shouldUseLocalIdentName = process.env.CSS_LOCAL_IDENT_NAME !== 'false';

const webpackDevClientEntry = require.resolve(
'react-dev-utils/webpackHotDevClient'
);
Expand Down Expand Up @@ -147,6 +149,11 @@ module.exports = function (webpackEnv) {
return loaders;
};

const getCssModulesIdentNameConfig = () =>
shouldUseLocalIdentName
? { getLocalIdent: getCSSModuleLocalIdent }
: { localIdentName: '[hash:base64]' };

return {
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
// Stop compilation early in production
Expand Down Expand Up @@ -518,9 +525,7 @@ module.exports = function (webpackEnv) {
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
},
modules: getCssModulesIdentNameConfig(),
}),
},
// Opt-in support for SASS (using .scss or .sass extensions).
Expand Down Expand Up @@ -554,9 +559,7 @@ module.exports = function (webpackEnv) {
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
},
modules: getCssModulesIdentNameConfig(),
},
'sass-loader'
),
Expand Down