diff --git a/packages/react-dev-utils/getCSSModuleLocalIdent.js b/packages/react-dev-utils/getCSSModuleLocalIdent.js index d1cd22a4e05..504bb1581e1 100644 --- a/packages/react-dev-utils/getCSSModuleLocalIdent.js +++ b/packages/react-dev-utils/getCSSModuleLocalIdent.js @@ -15,8 +15,10 @@ module.exports = function getLocalIdent( localName, options ) { - // Use the filename or folder name, based on some uses the index.js / index.module.css project style - const fileNameOrFolder = context.resourcePath.endsWith('index.module.css') + // Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style + const fileNameOrFolder = context.resourcePath.match( + /index\.module\.(css|scss|sass)$/ + ) ? '[folder]' : '[name]'; // Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique. diff --git a/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js b/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js index dc10c9a1b08..c8dd07f0922 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js @@ -50,6 +50,11 @@ describe('Integration', () => { ).to.match( /.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/ ); + expect( + doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '') + ).to.match( + /.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/ + ); }); it('sass inclusion', async () => { @@ -68,6 +73,11 @@ describe('Integration', () => { ).to.match( /.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/ ); + expect( + doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '') + ).to.match( + /.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/ + ); }); it('graphql files inclusion', async () => { diff --git a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/SassModulesInclusion.js b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/SassModulesInclusion.js index dd832eaea32..7f9837a7981 100644 --- a/packages/react-scripts/fixtures/kitchensink/src/features/webpack/SassModulesInclusion.js +++ b/packages/react-scripts/fixtures/kitchensink/src/features/webpack/SassModulesInclusion.js @@ -7,7 +7,13 @@ import React from 'react'; import styles from './assets/sass-styles.module.sass'; +import indexStyles from './assets/index.module.sass'; export default () => ( -
SASS Modules are working!
+SASS Modules are working!
++ SASS Modules with index are working! +
+SCSS Modules are working!
+SCSS Modules are working!
++ SCSS Modules with index are working! +
+