Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teplostanski/vite-plugin-pretty-module-classnames
💅 Adds the filename without the -module suffix to the class names of CSS modules
https://github.com/teplostanski/vite-plugin-pretty-module-classnames
css css-modules less plugin scss scss-modules vite vite-plugin
Last synced: 12 days ago
JSON representation
💅 Adds the filename without the -module suffix to the class names of CSS modules
- Host: GitHub
- URL: https://github.com/teplostanski/vite-plugin-pretty-module-classnames
- Owner: teplostanski
- License: mit
- Created: 2024-04-27T20:29:59.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-01-12T19:21:41.000Z (25 days ago)
- Last Synced: 2025-01-12T20:23:54.383Z (25 days ago)
- Topics: css, css-modules, less, plugin, scss, scss-modules, vite, vite-plugin
- Language: TypeScript
- Homepage: https://npmjs.com/package/vite-plugin-pretty-module-classnames
- Size: 234 KB
- Stars: 20
- Watchers: 1
- Forks: 2
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- fucking-awesome-vite - vite-plugin-pretty-module-classnames - Adds the filename without the `-module` suffix to the class names of CSS modules. (Plugins / Framework-agnostic Plugins)
- awesome-vite - vite-plugin-pretty-module-classnames - Adds the filename without the `-module` suffix to the class names of CSS modules. (Plugins / Framework-agnostic Plugins)
README
vite-plugin-pretty-module-classnames
[
](https://npmjs.com/package/vite-plugin-pretty-module-classnames)
[](https://npmjs.com/package/vite-plugin-pretty-module-classnames)
[](https://npmjs.com/package/vite-plugin-pretty-module-classnames)
[](https://npmjs.com/package/vite-plugin-pretty-module-classnames)
[](https://github.com/teplostanski/vite-plugin-pretty-module-classnames)
[](https://github.com/teplostanski/vite-plugin-pretty-module-classnames)
[](https://github.com/teplostanski/vite-plugin-pretty-module-classnames/issues)
[](https://github.com/teplostanski/vite-plugin-pretty-module-classnames/pulls)
Adds the filename without the
-module
suffix to the class names of CSS modules.
Included in the Awesome Vite.js list![]()
## 📦 Installation
[npmjs.com](https://npmjs.com/package/vite-plugin-pretty-module-classnames) • [yarnpkg.com](https://yarnpkg.com/package?q=vite-plugin-pretty-module-classnames&name=vite-plugin-pretty-module-classnames)
```bash
npm install -D vite-plugin-pretty-module-classnames
```## 🦾 Features
- Framework-agnostic
- Tested: `VanillaJS`, `React`, `Vue`
- Potentially works with any framework. If you have any problems, write to the [Issue](https://github.com/teplostanski/vite-plugin-pretty-module-classnames/issues)
- Support `CommonJS` and `ES Modules`
- Support `Vite 2.x`
- Configurable: Added support for plugin configuration## 🤔 Why Use This?
As utilizing CSS modules in React, we're accustomed to seeing class names formatted as `SomeComponent__classname_hash`. However, with Vite, the naming convention for modular class names appears slightly different, resembling `__classname_hash` or `SomeComponent-module__classname_hash` the latter occurring if `generateScopedName: '[name]__[local]_[hash:base64:5]'` is specified in vite.config.js. This addition of `-module` post-component name can be cumbersome to work around.
Fortunately, the `vite-plugin-pretty-module-classnames` provides a solution to this issue!
## ⚙️ Usege
###### Api
```js
// vite.config.js
import prettyModuleClassnames from "vite-plugin-pretty-module-classnames";
```###### Example
```js
// vite.config.js
export default defineConfig({
plugins: [prettyModuleClassnames()],
});
```## 🔧 Configuration
### `lineNumber` Option
The `lineNumber` option is a boolean that, when set to `true`, appends the line number where the CSS class is defined in the source file to the generated class name.
###### Example
```js
// vite.config.js
import prettyModuleClassnames from "vite-plugin-pretty-module-classnames";export default defineConfig({
plugins: [prettyModuleClassnames({ lineNumber: true })],
});
```With this configuration, if your CSS file contains:
```css
/* SomeComponent.module.css */
1 .wrapper {
2 /* styles */
3 }
4
5 .container {
6 /* styles */
7 }
```The generated class names will look like:
- SomeComponent__wrapper_abcd1_1
- SomeComponent__container_abcd2_5> [!WARNING]
> Please note that the `lineNumber` option mirrors the behavior of Vite's default class name generation when using preprocessors like Sass, Less, or Stylus. The line number is calculated based on the compiled CSS, where empty lines between selectors and comments are typically removed. This can lead to discrepancies between the line numbers in the source files and the compiled output, potentially resulting in inaccurate line numbers in the generated class names.
>
> Additionally, in Vue files, the line count always starts from the `` tag, regardless of where it is placed within the file. This means that the line numbers in generated class names will be relative to the position of the `<style module>` tag, not the beginning of the file.## 🤝 Contributing
Want to contribute? Awesome! To show your support is to star the project, or to raise [issues on GitHub](https://github.com/teplostanski/vite-plugin-pretty-module-classnames/issues).
Before you contribute to the development of the project, read the [rules](https://github.com/teplostanski/vite-plugin-pretty-module-classnames/blob/main/CONTRIBUTING.md).
Thanks again for your support, it is much appreciated! 🙏
<h2> © License</h2>
<a href="https://github.com/teplostanski/vite-plugin-pretty-module-classnames/blob/main/LICENSE">MIT</a> License © 2024 <a href="https://github.com/teplostanski">teplostanski</a><h2> ❤ Fund this project</h2>
<a href="https://donate.teplostanski.dev" target="_blank">donate.teplostanski.dev</a>