11# esbuild-css-modules-plugin
22
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 )
3+ [ ![ npm version] ( https://img.shields.io/npm/v/esbuild-css-modules-plugin )] ( https://www.npmjs.com/package/esbuild-css-modules-plugin )
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
66A esbuild plugin to bundle css modules into js(x)/ts(x).
77
88Works both with ` bundle: false ` and ` bundle: true ` .
99
10- If build with ` bundle: false ` , ` xxx.modules.css ` will be transformed to ` xxx.modules.js ` .
10+ If build with ` bundle: false ` , ` xxx.modules.css ` will be transformed to ` xxx.modules.css. js ` .
1111
12- See [ ` ./test/test.js ` ] ( https://github.com/indooorsman/esbuild-css-modules-plugin/blob/v3 /test/test.js ) for examples.
12+ See [ ` ./test/test.js ` ] ( https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main /test/test.js ) for examples.
1313
1414## Install
1515
1616``` shell
17- npm i -D esbuild-css-modules-plugin@v3-dev
17+ npm i -D esbuild-css-modules-plugin
1818```
1919
2020or
2121
2222``` shell
23- yarn add -D esbuild-css-modules-plugin@v3-dev
23+ yarn add -D esbuild-css-modules-plugin
2424```
2525
2626## Usage
@@ -32,78 +32,12 @@ import CssModulesPlugin from 'esbuild-css-modules-plugin';
3232esbuild .build ({
3333 plugins: [
3434 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 typescript declaration file for css file to `outdir` of esbuild config. 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'
83- },
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 ,
104-
105- /** Optional. Regex to filter certain CSS files. default is `/\.modules?\.css$/i` */
106- filter: / \. modules? \. css$ / i
35+ // @see https://github.com/indooorsman/esbuild-css-modules-plugin/blob/main/index.d.ts for more details
36+ force: true ,
37+ emitDeclarationFile: true ,
38+ localsConvention: ' camelCaseOnly' ,
39+ namedExports: true ,
40+ inject: false
10741 })
10842 ]
10943});
0 commit comments