esbuild-plugin-auto-css-modules
Version:
Automatically import styles filename mark CSS modules. After adding the flag, the build tool can distinguish whether to enable css Modules
57 lines (42 loc) • 1.96 kB
Markdown
# esbuild-plugin-auto-css-modules
[](https://badge.fury.io/js/esbuild-plugin-auto-css-modules)
[](https://opensource.org/licenses/MIT)
[](https://github.com/noyobo/esbuild-plugin-auto-css-modules/issues)
[](#contributing)
[](https://www.npmjs.com/package/esbuild-plugin-auto-css-modules)
[](https://codecov.io/gh/noyobo/esbuild-plugin-auto-css-modules)
[](https://github.com/noyobo/esbuild-plugin-auto-css-modules/actions/workflows/node.js.yml)
Automatically import styles filename mark CSS modules. After adding the flag, the build tool can distinguish whether to enable css Modules
## Install
```bash
npm i esbuild-plugin-auto-css-modules -D
```
## Usage
```js
import { build } from 'esbuild'
import { autoCssModules } from 'esbuild-plugin-auto-css-modules'
build({
entryPoints: ['src/index.js'],
bundle: true,
outfile: 'dist/index.js',
plugins: [autoCssModules()],
}).catch(() => process.exit(1))
```
```js
// before
import styles from './index.css';
```
```js
// after
import styles from './index.css?modules';
```
## Options
```ts
type Options = {
filter?: RegExp; // default: /\.([tj]sx?)$/
flag?: string; // default: modules
ignore?: RegExp | ((filename: string) => boolean); // default: null
}
```
## Related
- [esbuild-style-loader](https://npmjs.com/package/esbuild-style-loader) - esbuild style loader plugin