mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-01 12:42:50 +08:00
Update CSS Modules localIndetName (#4192)
* Update CSS Modules localIndetName * Add missing file to package * Correct regex * plz plz plz
This commit is contained in:
37
packages/react-dev-utils/getCSSModuleLocalIdent.js
vendored
Normal file
37
packages/react-dev-utils/getCSSModuleLocalIdent.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const loaderUtils = require('loader-utils');
|
||||
|
||||
module.exports = function getLocalIdent(
|
||||
context,
|
||||
localIdentName,
|
||||
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')
|
||||
? '[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.
|
||||
const hash = loaderUtils.getHashDigest(
|
||||
context.resourcePath + localName,
|
||||
'md5',
|
||||
'base64',
|
||||
5
|
||||
);
|
||||
// Use loaderUtils to find the file or folder name
|
||||
const className = loaderUtils.interpolateName(
|
||||
context,
|
||||
fileNameOrFolder + '_' + localName + '__' + hash,
|
||||
options
|
||||
);
|
||||
// remove the .module that appears in every classname when based on the file.
|
||||
return className.replace('.module_', '_');
|
||||
};
|
||||
Reference in New Issue
Block a user