Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@ecomfe/class-names-loader
Advanced tools
Webpack loader to transform style into classNames bindings
Webpack loader to transform style into classNames bindings.
Inspired by itsmepetrov/classnames-loader and have a total written to introduce features and breaking changes like:
style-loader
's esModule
format only.We will keep active maintain.
npm install -D class-names-loader
This loader is to bind a CSS modules enabled style-loader
output into a classnames
compatible function, received class names are mapped to CSS modules transformed ones:
import c from './index.css';
// May renders as `<div class="title-0f2bd">
<div className={c('title')} />
This function is also a mapping object from raw class names to transformed ones, so c.title
is identical to c('title')
.
Also it behaves like classnames
and accept more complex arguments like c('title', {emphasis: props.isHeading}, props.className)
. Any class names not in CSS file are rended as is, c('some-class')
returns "some-class"
.
A traditional webpack configuration looks like:
{
module: {
rules: [
{
test: /\.css$/,
use: [
{
loader: 'class-names-loader',
options: {
// options
},
},
{
loader: 'style-loader',
modules: true,
},
{
loader: 'css-loader',
modules: true,
},
],
},
],
},
}
style-loader >= 2
enables esModule
option by default, and it must be enabled when combine with class-names-loader
.
interface Options {
// Custom classnames module path, by default it imports `classnames`
classNamesModule?: string;
// Use named import from style-loader
namedImport?: boolean;
}
By default we require classnames
module to be installed and import it, you can also install a custom module and pass it's module path to classNameModule
option.
This is especially useful when you create a custom build tool and want to encapsulate classnames
inside this tool:
// Build tool with class-names-loader and classnames installed locally
{
loader: require.resolve('class-names-loader'),
options: {
classNamesModule: require.resolve('classnames'),
},
}
If you have namedExport
option enabled in style-loader
, you should also enable namedImport
option to make it compatible.
FAQs
Webpack loader to transform style into classNames bindings
We found that @ecomfe/class-names-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.