Skip to content

Commit acf5070

Browse files
committed
readme for v3
1 parent 4c7f062 commit acf5070

File tree

1 file changed

+78
-43
lines changed

1 file changed

+78
-43
lines changed

readme.md

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# esbuild-css-modules-plugin
22

3-
[![npm version](https://img.shields.io/npm/v/esbuild-css-modules-plugin.svg?v=2.5.0)](https://www.npmjs.com/package/esbuild-css-modules-plugin)
3+
[![npm version](https://img.shields.io/npm/v/esbuild-css-modules-plugin/v3-dev)](https://www.npmjs.com/package/esbuild-css-modules-plugin/v/v3-dev)
44
[![Test](https://github.com/indooorsman/esbuild-css-modules-plugin/actions/workflows/test.yml/badge.svg)](https://github.com/indooorsman/esbuild-css-modules-plugin/actions/workflows/test.yml)
55

66
A esbuild plugin to bundle css modules into js(x)/ts(x).
@@ -14,62 +14,97 @@ See [`./test/test.js`](https://github.com/indooorsman/esbuild-css-modules-plugin
1414
## Install
1515

1616
```shell
17-
npm i -D esbuild-css-modules-plugin
17+
npm i -D esbuild-css-modules-plugin@v3-dev
1818
```
1919

2020
or
2121

2222
```shell
23-
yarn add -D esbuild-css-modules-plugin
23+
yarn add -D esbuild-css-modules-plugin@v3-dev
2424
```
2525

2626
## Usage
2727

28-
````js
29-
const esbuild = require('esbuild');
30-
const cssModulesPlugin = require('esbuild-css-modules-plugin');
28+
```js
29+
import esbuild from 'esbuild';
30+
import CssModulesPlugin from 'esbuild-css-modules-plugin';
3131

3232
esbuild.build({
3333
plugins: [
34-
cssModulesPlugin({
35-
// optional. set to false to not inject generated css into page;
36-
// default value is false when set `v2` to `true`, otherwise default is true,
37-
// if set to `true`, the generated css will be injected into `head`;
38-
// could be a string of css selector of the element to inject into,
39-
// e.g.
40-
// ```
41-
// inject: '#some-element-id' // the plugin will try to get `shadowRoot` of the found element, and append css to the `shadowRoot`, if no shadowRoot then append to the found element, if no element found then append to document.head
42-
// ```
43-
// could be a function with params content & digest (return a string of js code to inject to page),
44-
// e.g.
45-
// ```
46-
// inject: (cssContent, digest) => `console.log("${cssContent}", "${digest}")`
47-
// ```
48-
inject: false,
49-
50-
localsConvention: 'camelCaseOnly', // optional. value could be one of 'camelCaseOnly', 'camelCase', 'dashes', 'dashesOnly', default is 'camelCaseOnly'
51-
52-
generateScopedName: (name, filename, css) => string, // optional. refer to: https://github.com/madyankin/postcss-modules#generating-scoped-names
53-
54-
filter: /\.modules?\.css$/i // Optional. Regex to filter certain CSS files.
55-
56-
cssModulesOption: {
57-
// optional, refer to: https://github.com/madyankin/postcss-modules/blob/d7cefc427c43bf35f7ebc55e7bda33b4689baf5a/index.d.ts#L27
58-
// this option will override others passed to postcss-modules
34+
CssModulesPlugin({
35+
/** optional, force to build modules-css files even if `bundle` is disabled in esbuild. default is `false` */
36+
force: false,
37+
/** optional, inline images imported in css as data url even if `bundle` is false. default is `false` */
38+
forceInlineImages: false,
39+
/** optional, generate declaration file for css file. default is `false` */
40+
emitDeclarationFile: false,
41+
/**
42+
* optional
43+
* @see https://lightningcss.dev/css-modules.html#local-css-variables
44+
*/
45+
dashedIndents: false,
46+
/**
47+
* optional, pattern of class names
48+
* The currently supported segments are:
49+
* [name] - the base name of the CSS file, without the extension
50+
* [hash] - a hash of the full file path
51+
* [local] - the original class name
52+
* @see https://lightningcss.dev/css-modules.html#custom-naming-patterns
53+
*/
54+
pattern: '[name]_[local]_[hash]',
55+
/**
56+
* optional, localsConvention
57+
* default is `camelCaseOnly`
58+
* **cameCase** : `.some-class-name` ==> `someClassName`, the original class name will not to be removed from the locals
59+
* **camelCaseOnly**: `.some-class-name` ==> `someClassName`, the original class name will be removed from the locals
60+
* **pascalCase** : `.some-class-name` ==> `SomeClassName`, the original class name will not to be removed from the locals
61+
* **pascalCaseOnly**: `.some-class-name` ==> `SomeClassName`, the original class name will be removed from the locals
62+
*/
63+
localsConvention: 'camelCase' | 'pascalCase' | 'camelCaseOnly' | 'pascalCaseOnly',
64+
/**
65+
* optional, enable named exports
66+
* @default false
67+
* @description
68+
* e.g.:
69+
* ```
70+
* export const someClassName = '.some-class-name__hauajsk';
71+
* ```
72+
* Notes:
73+
* - `someClassName` can **NOT** be a js key word like `const`, `var` & etc.
74+
* - can **NOT** be used with `inject`
75+
*/
76+
namedExports: false,
77+
// optional, package info
78+
package: {
79+
name: 'my-lib',
80+
main: 'index.cjs',
81+
module: 'index.js',
82+
version: '3.0.0'
5983
},
84+
/**
85+
* optional. set to false to not inject generated css into page;
86+
* if set to `true`, the generated css will be injected into `head`;
87+
* could be a string of css selector of the element to inject into,
88+
* e.g.
89+
*
90+
* ```
91+
* inject: '#some-element-id' // the plugin will try to get `shadowRoot` of the found element, and append css to the
92+
* `shadowRoot`, if no shadowRoot then append to the found element, if no element found then append to document.head
93+
*
94+
* ```
95+
*
96+
* could be a function with params content & digest (return a string of js code to inject css into page),
97+
* e.g.
98+
*
99+
* ```
100+
* inject: (content, digest) => `console.log(${content}, ${digest})`
101+
* ```
102+
*/
103+
inject: false,
60104

61-
v2: true, // experimental. v2 can bundle images in css, note if set `v2` to true, other options except `inject` will be ignored. and v2 only works with `bundle: true`.
62-
v2CssModulesOption: { // Optional.
63-
dashedIndents: false, // Optional. refer to: https://github.com/parcel-bundler/parcel-css/releases/tag/v1.9.0
64-
/**
65-
* Optional. The currently supported segments are:
66-
* [name] - the base name of the CSS file, without the extension
67-
* [hash] - a hash of the full file path
68-
* [local] - the original class name
69-
*/
70-
pattern: `custom-prefix_[local]_[hash]`
71-
}
105+
/** Optional. Regex to filter certain CSS files. */
106+
filter: /\.modules?\.css$/i
72107
})
73108
]
74109
});
75-
````
110+
```

0 commit comments

Comments
 (0)