-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetCSSModuleLocalIdent.js
More file actions
34 lines (31 loc) · 988 Bytes
/
getCSSModuleLocalIdent.js
File metadata and controls
34 lines (31 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* 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')
const path = require('path')
module.exports = function getLocalIdent(
context,
localIdentName,
localName,
options
) {
// 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(
path.posix.relative(context.rootContext, context.resourcePath) + localName,
'md5',
'base64',
5
)
// Use loaderUtils to find the file or folder name
const className = loaderUtils.interpolateName(
context,
localName + '__' + hash,
options
)
// Remove the .module that appears in every classname when based on the file and replace all "." with "_".
return className.replace('.module_', '_').replace(/\./g, '_')
}