A [SWC](https://swc.rs) plugin to use [CSS Modules](https://github.com/css-modules/css-modules).
npm install swc-plugin-css-modulesA SWC plugin to use CSS Modules.
Instead of creating an object, the plugin injects the css class names directly into the js code.
This allows to reduce the size of the bundle.
`` // Output ↓ ↓ ↓ ↓ ↓ ↓ npm: yarn: You can check the compatibility of versions on https://plugins.swc.rs/ Via Using css modules in code: // ✅ ok // ✅ ok // ⛔ Computed hit cannot be injected // ⛔ Computed hit cannot be injected // ✅ ok // ⛔ Computed hit cannot be injected Default: Allows to configure the generated local ident name. Supported template strings: - Supported hash functions: - Supported hash digests: - Add custom hash prefix to generate more unique classes. Default: If you need, you can pass any needed root path.js
// Input Code
import styles from "./style.css";
element.innerHTML = '';
import "./style.css";
element.innerHTML = '';
``Installation
sh`
npm i -D swc-plugin-css-modules`sh`
yarn add -D swc-plugin-css-modules.swcrcUsage
`json`
{
"jsc": {
"experimental": {
"plugins": [
[
"swc-plugin-css-modules",
{
"generate_scoped_name": "[name]__[local]___[hash:base64:5]"
}
]
]
}
}
}`js`
import styles from "./style.module.css";
const className = styles.className;
const className = styles["class-name"];
const className = styles["class" + "Name"];
const className = styles[localClassName];
const className = classNames(styles.title, styles.className);
const className = getClassNameFromCssModules(styles);"[hash:base64]"Options
$3
[name] the basename of the resource[folder]
- the folder the resource relative[ext]
- - extension with leading[hash]
- - the hash of the string(by default it's the hex digest of the xxhash64 hash)[
- - hash with hash settings[local]
- - original classxxhash64md4
- md5
- sha1
- sha224
- sha256
- sha384
- sha512
- hexbase32
- base64
- ".css"`$3
$3
$3