fix(cli): use content-based hashing for CSS module class names
Replace the default path-based CSS module hash with a content-based hash derived from the CSS content. This prevents class name collisions when multiple versions of packages are loaded simultaneously. Uses 10 characters of hex-encoded MD5 hash for safe, readable class name suffixes. Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Fixed CSS module class name collisions when running multiple versions of packages simultaneously by using content-based hashing for class name generation.
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
import chalk from 'chalk';
|
||||
import fs from 'fs-extra';
|
||||
import { createHash } from 'crypto';
|
||||
import {
|
||||
basename,
|
||||
extname,
|
||||
relative as relativePath,
|
||||
resolve as resolvePath,
|
||||
@@ -239,7 +241,18 @@ export async function makeRollupConfigs(
|
||||
include: /node_modules/,
|
||||
exclude: [/\/[^/]+\.(?:stories|test)\.[^/]+$/],
|
||||
}),
|
||||
postcss(),
|
||||
postcss({
|
||||
modules: {
|
||||
generateScopedName(name: string, filename: string, css: string) {
|
||||
const hash = createHash('md5')
|
||||
.update(css)
|
||||
.digest('hex')
|
||||
.slice(0, 10);
|
||||
const file = basename(filename, '.module.css');
|
||||
return `${file}_${name}__${hash}`;
|
||||
},
|
||||
},
|
||||
}),
|
||||
forwardFileImports({
|
||||
exclude: /\.icon\.svg$/,
|
||||
include: [
|
||||
|
||||
Reference in New Issue
Block a user