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

esbuild-plugin-class-modules

v2.1.9

Published

> An esbuild plugin to compile your css stylesheets using [Sass-lang](https://sass-lang.com/documentation/js-api/modules#compile), [PostCSS](https://postcss.org) and [CSS Modules.](https://github.com/css-modules/css-modules) > Supports global and local sc

Downloads

2,896

Readme

Description

An esbuild plugin to compile your css stylesheets using Sass-lang, PostCSS and CSS Modules.
Supports global and local scoped outputs.

Installation

yarn add -D esbuild-plugin-class-modules
# or
npm install -D esbuild-plugin-class-modules

Usage

const esbuild = require("esbuild");
const { classModules } = require("esbuild-plugin-class-modules");

esbuild
  .build({
    entryPoints: ["input.js"],
    outdir: "public",
    bundle: true,
    plugins: [classModules()],
  })
  .then((result) => console.log(result))
  .catch(() => process.exit(1));

You can also customize Sass compiler, PostCSS and CssModules options.

const cssCompilerOptions = {
  options: {
    sass: {},
    postcss: [],
    cssModules: {

    }
  },
}

// usual esbuild config
{
 ...
 plugins: [classModules(cssCompilerOptions)],
 ...
}

By default following file extensions will be considered by the compiler:

- .css
- .module.css
- .modules.css
- .scss
- .module.scss
- .modules.scss
- .sass

using the regex /(\.modules?)?\.((s)?css|sass)$/i .
To customize this filter passe filter regex into plugin options.
Example to handle only .scss files:

const cssCompilerOptions = {
  filter: /\.scss$/i,
  options: {
    sass: {},
    postcss: [],
    cssModules: {},
  },
};

Local and Global scops

By default any file ending with .global.css scss etc. is considered as global. To customize this behavior set globalModulePaths into plugins cssModules.
Default is [/\.global\.(s?css|sass)$/].
See CSS Modules for more info.

Another way to declare class names as global scoped is to use nameless import/require.
Ex:

import "./myAwsomeStyles.scss";

or as local scoped with named import/require:

import style from "./myAwsomeStyles.scss";

Usage with multiple css processor plugins

For better compatibility with other css processors it's prefered to put esbuild-plugin-class-modules at after all other css plugins in your esbuild config.

const esbuild = require("esbuild");
const lessCssPlugin = require("some-less-processor-plugin");
const { classModules } = require("esbuild-plugin-class-modules");

esbuild
  .build({
    entryPoints: ["input.js"],
    outdir: "public",
    bundle: true,
    plugins: [lessCssPlugin, classModules()],
  })
  .then((result) => console.log(result))
  .catch(() => process.exit(1));