npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-pretty-module-classnames

v1.3.0

Published

Adds the filename without the -module suffix to the class names of CSS modules.

Downloads

20,078

Readme

📦 Installation

npmjs.com

npm install -D vite-plugin-pretty-module-classnames

🦾 Features

  • Framework-agnostic
    • Tested: without frameworks, React, Vue
    • Potentially works with any framework. If you have any problems, write to the Issue
  • 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
// vite.config.js
import prettyModuleClassnames from "vite-plugin-pretty-module-classnames";
Example
// 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
// 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:

/* 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 may not work correctly with 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 <style module> 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.

Before you contribute to the development of the project, read the rules.

Thanks again for your support, it is much appreciated! 🙏