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

css-module-transformer

v1.0.1

Published

A tool that automates the conversion of your codebase to CSS Modules. It seamlessly transforms imports and class names, ensuring styles are scoped to their corresponding components and improving code maintainability.

Downloads

6

Readme

css-modules-transformer

npm version License

Easily transition your codebase to CSS Modules for modular, maintainable styles!

Say goodbye to messy, global styles and hello to the power of CSS Modules! This handy NPM package seamlessly transforms your JavaScript files to utilize scoped styles, making your codebase cleaner, more maintainable, and conflict-free. Managing CSS in larger projects can become cumbersome. Traditional CSS often leads to style bleed, where styles intended for one component affect others unintentionally. Additionally, manually handling CSS imports and class names across multiple files can be tedious and error-prone.

✨ What it does:

  • Automatically converts className="example" to className={styles.example} for static class names.
  • Smartly handles dynamic class names: className={dynamic-ClassName} or className="dynamic-ClassName" becomesclassName={styles[dynamic-ClassName]} .
  • Updates regular CSS imports to module-specific ones for proper integration, Ensures correct file paths and extensions for seamless usage.
  • No more manual replacements! Sit back and relax while css-modules-transformer does the heavy lifting.

🌐 Example

Before:

import react from 'react';
import { render } from 'react-dom';
import './long/relative/path/styles.css';

const DummyComponent = () => {
    return (
        <div className="container">
            <div className="header-text">
            <h1>Hello, World!</h1>
            </div>
        </div>
    );
};

export default DummyComponent;

After:

import react from 'react';
import styles from './long/relative/path/styles.module.css'; 

const DummyComponent = () => {
    return (
        <div className={styles.container}>
            <div className={styles["header-text"]}>
            <h1>Hello, World!</h1>
            </div>
        </div>
    );
};

export default DummyComponent;

🛠️ Getting Started:

  1. Install css-modules-transformer globally
    npm install -g css-modules-transformer
  2. Transform a file:
    npx transform ./path/to/your-file.jsx
  3. Witness the magic! ✨

Benefits:

  • Modular Styles: Each component owns its styles, preventing bleed and unintended conflicts.
  • Improved Maintainability: Easier to find and update styles specific to individual components.
  • Scalable Codebase: Manage large projects with confidence, thanks to organized and isolated styles.

🚀 Upcoming Features:

We're actively working on expanding the package's capabilities:

  • Recursive Directory Handling: Transform multiple files within directories for effortless codebase-wide conversion.
  • Customize transformations with configuration options
  • Build Tool Integration: Seamlessly integrate with popular build tools like Webpack and Rollup for streamlined workflows.
  • Customizable Class Name Formatting: Control how generated class names are formatted for greater flexibility and alignment with project conventions.

📝 Additional Notes

  • Remember to rename your CSS files with the .module.css extension to ensure compatibility with CSS Modules.
  • Adjust your build process to handle CSS Modules appropriately, typically using a plugin or loader.
  • Thoroughly test your transformed components to guarantee styles function as expected.

📝 Limitations and Edge Cases:

  • Currently supports single-file transformation.
  • Doesn't handle nested imports or complex directory structures (yet!).
  • Manual adjustments might be required for intricate codebases.

🌍 Support

  • If you encounter any issues or have questions, feel free to open an issue