From f642660e97d7786bed4d129a19c6a9834e2548df Mon Sep 17 00:00:00 2001 From: zamarawka Date: Fri, 26 Jun 2020 07:29:38 +0300 Subject: [PATCH 1/2] feat(react-scripts): Provide way to obfuscate css modules ident names. --- packages/react-scripts/config/webpack.config.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 2c32b66ac9a..4d219bccc68 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -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' ); @@ -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 @@ -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). @@ -554,9 +559,7 @@ module.exports = function (webpackEnv) { sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment, - modules: { - getLocalIdent: getCSSModuleLocalIdent, - }, + modules: getCssModulesIdentNameConfig(), }, 'sass-loader' ), From 60e922ce40ccddd67af2bcd4764779121a538095 Mon Sep 17 00:00:00 2001 From: zamarawka Date: Fri, 26 Jun 2020 07:31:54 +0300 Subject: [PATCH 2/2] docs: Add description for css ident obfuscation. --- docusaurus/docs/advanced-configuration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docusaurus/docs/advanced-configuration.md b/docusaurus/docs/advanced-configuration.md index 958f9ac3168..afa2a18698e 100644 --- a/docusaurus/docs/advanced-configuration.md +++ b/docusaurus/docs/advanced-configuration.md @@ -22,6 +22,7 @@ You can adjust various development and production settings by setting environmen | REACT_EDITOR | βœ… Used | 🚫 Ignored | When an app crashes in development, you will see an error overlay with clickable stack trace. When you click on it, Create React App will try to determine the editor you are using based on currently running processes, and open the relevant source file. You can [send a pull request to detect your editor of choice](https://github.com/facebook/create-react-app/issues/2636). Setting this environment variable overrides the automatic detection. If you do it, make sure your systems [PATH]() environment variable points to your editor’s bin folder. You can also set it to `none` to disable it completely. | | CHOKIDAR_USEPOLLING | βœ… Used | 🚫 Ignored | When set to `true`, the watcher runs in polling mode, as necessary inside a VM. Use this option if `npm start` isn't detecting changes. | | GENERATE_SOURCEMAP | 🚫 Ignored | βœ… Used | When set to `false`, source maps are not generated for a production build. This solves out of memory (OOM) issues on some smaller machines. | +| CSS_LOCAL_IDENT_NAME | βœ… Used | βœ… Used | When set to `false`, css modules don't generate full path to component in ident names (e.g. class names). Ident names obfuscated/minified, not readable. | | INLINE_RUNTIME_CHUNK | 🚫 Ignored | βœ… Used | By default, Create React App will embed the runtime script into `index.html` during the production build. When set to `false`, the script will not be embedded and will be imported as usual. This is normally required when dealing with CSP. | | IMAGE_INLINE_SIZE_LIMIT | 🚫 Ignored | βœ… Used | By default, images smaller than 10,000 bytes are encoded as a data URI in base64 and inlined in the CSS or JS build artifact. Set this to control the size limit in bytes. Setting it to 0 will disable the inlining of images. | | EXTEND_ESLINT | βœ… Used | βœ… Used | When set to `true`, user provided ESLint configs will be used by `eslint-loader`. Note that any rules set to `"error"` will stop the application from building. |