OptionalfileOptionalgenerateoptional function to generate scoped name
OptionalhashLength: numberOptionalhashgenerated scope hash length. the default is 5
Optionalnamingoptional. function change the case of the scoped name and the class mapping
Optionalpatternthe pattern used to generate scoped names. the supported placeholders are:
the pattern can optionally have a maximum number of characters:
pattern: '[local:2]-[hash:5]'
the hash pattern can take an algorithm, a maximum number of characters or both:
pattern: '[local]-[hash:base64:5]'
or
pattern: '[local]-[hash:5]'
or
pattern: '[local]-[hash:sha1]'
supported hash algorithms are:
import {transform, ModuleCaseTransformEnum} from '@tbela99/css-parser';
import type {TransformResult} from '@tbela99/css-parser';
css = `
:local(.className) {
background: red;
color: yellow;
}
:local(.subClass) {
composes: className;
background: blue;
}
`;
let result: TransformResult = await transform(css, {
beautify:true,
module: {
pattern: '[local]-[hash:sha256]'
}
});
console.log(result.code);
generated css
.className-b629f {
background: red;
color: #ff0
}
.subClass-a0c35 {
background: blue
}
Optionalscopeduse local scope vs global scope
module output file path. it is used to generate the scoped name. if not provided, options.src will be used