2.1.9 • Published 11 months ago

esbuild-plugin-class-modules v2.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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));
2.1.9

11 months ago

2.1.4

12 months ago

2.1.6

12 months ago

2.1.5

12 months ago

2.1.8

12 months ago

2.1.7

12 months ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.3

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

2.0.0-alpha.0

1 year ago

2.0.0-alpha.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago