Skip to content

WRQ-200: Apply own hash on css-module-ident.js #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# unreleased

* `css-module-ident`: Added own hash generate function.
* Removed eslint related modules.

# 6.0.3 (December 21, 2023)
Expand Down
17 changes: 16 additions & 1 deletion css-module-ident.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const loaderUtils = require('loader-utils');
const app = require('./option-parser');
const packageRoot = require('./package-root');

Expand All @@ -24,5 +25,19 @@ module.exports = function (context, localIdentName, localName) {
}
const fileMatch = rel.match(fileIdentPattern);
const identFile = (fileMatch && (fileMatch[1] || fileMatch[2])) || 'unknown';
return identFile.replace(/[/\\]+/g, '_') + '_' + localName;

// Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
let hash = '';
if (process.env.SIMPLE_CSS_IDENT !== 'true') {
hash =
'__' +
loaderUtils.getHashDigest(
path.posix.relative(context.rootContext, context.resourcePath) + localName,
'md5',
'base62',
5
);
}

return identFile.replace(/[/\\]+/g, '_') + '_' + localName + hash;
};
Loading