Skip to content

Commit a084df6

Browse files
committed
merge v3 to main
1 parent 5461f68 commit a084df6

File tree

12 files changed

+195
-216
lines changed

12 files changed

+195
-216
lines changed

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## V3.0.0
2+
This version has some breaking changes:
3+
- drop postcss-module, as a result most of postcss-module configurations are removed as well
4+
- remove `v2` feature flag
5+
6+
Other changes:
7+
- full support of `compose`
8+
- code refactor
9+
- export both `commonjs` & `es` module
10+
111
## V2.7.1
212
- support esbuild@^0.17
313

index.d.ts

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,92 @@
11
import type { Plugin, PluginBuild } from 'esbuild';
22

33
declare interface BuildOptions {
4-
/** force to build modules-css files even if `bundle` is disabled in esbuild, default is `false` */
4+
/**
5+
* force to build css modules files even if `bundle` is disabled in esbuild
6+
* @default false
7+
*/
58
force?: boolean;
6-
/** inline images imported in css as data url even if `bundle` is false */
9+
/**
10+
* inline images imported in css as data url even if `bundle` is false
11+
* @default false
12+
*/
713
forceInlineImages?: boolean;
814
/**
915
* emit typescript declaration file for css modules class names
1016
* - `.css.d.ts` : emit `xxx.css.d.ts`
1117
* - `.d.css.ts` : emit `xxx.d.css.ts` (from typescript@5, see https://www.typescriptlang.org/tsconfig#allowArbitraryExtensions)
1218
* - `true` : emit both `xxx.css.d.ts` and `xxx.d.css.ts`
19+
* @default false
1320
*/
1421
emitDeclarationFile?: boolean | '.d.css.ts' | '.css.d.ts';
22+
/**
23+
* set to false to not inject generated css into page;
24+
* @description
25+
* if set to `true`, the generated css will be injected into `head`;
26+
* could be a string of css selector of the element to inject into,
27+
* e.g.
28+
*
29+
* ``` js
30+
* {
31+
* inject: '#some-element-id'
32+
* }
33+
*
34+
* ```
35+
* the plugin will try to get `shadowRoot` of the found element, and append css to the
36+
* `shadowRoot`, if no shadowRoot then append to the found element, if no element found then append to `document.head`.
37+
*
38+
* could be a function with params content & digest (return a string of js code to inject css into page),
39+
* e.g.
40+
*
41+
* ```js
42+
* {
43+
* inject: (content, digest) => `console.log(${content}, ${digest})`
44+
* }
45+
* ```
46+
* @default false
47+
*/
1548
inject?: boolean | string | ((css: string, digest: string) => string);
49+
/**
50+
* Regex to filter certain CSS files.
51+
* @default /\.modules?\.css$/i
52+
*/
1653
filter?: RegExp;
1754
/**
18-
* refer to: https://github.com/parcel-bundler/parcel-css/releases/tag/v1.9.0
55+
* @see https://lightningcss.dev/css-modules.html#local-css-variables
1956
*/
2057
dashedIndents?: boolean;
2158
/**
2259
* The currently supported segments are:
2360
* [name] - the base name of the CSS file, without the extension
2461
* [hash] - a hash of the full file path
2562
* [local] - the original class name
63+
* @see https://lightningcss.dev/css-modules.html#custom-naming-patterns
2664
*/
2765
pattern?: string;
2866
/**
2967
* localsConvention
30-
* default is `camelCaseOnly`
31-
* **cameCase** : `.some-class-name` ==> `someClassName`, the original class name will not to be removed from the locals
32-
* **camelCaseOnly**: `.some-class-name` ==> `someClassName`, the original class name will be removed from the locals
33-
* **pascalCase** : `.some-class-name` ==> `SomeClassName`, the original class name will not to be removed from the locals
34-
* **pascalCaseOnly**: `.some-class-name` ==> `SomeClassName`, the original class name will be removed from the locals
68+
* - **cameCase** : `.some-class-name` ==> `someClassName`, the original class name will not to be removed from the locals
69+
* - **camelCaseOnly**: `.some-class-name` ==> `someClassName`, the original class name will be removed from the locals
70+
* - **pascalCase** : `.some-class-name` ==> `SomeClassName`, the original class name will not to be removed from the locals
71+
* - **pascalCaseOnly**: `.some-class-name` ==> `SomeClassName`, the original class name will be removed from the locals
72+
* @default "camelCaseOnly"
3573
*/
3674
localsConvention?: 'camelCase' | 'pascalCase' | 'camelCaseOnly' | 'pascalCaseOnly';
3775
/**
3876
* namedExports
39-
* @default false
40-
* @description
4177
* e.g.:
4278
* ```
4379
* export const someClassName = '.some-class-name__hauajsk';
4480
* ```
81+
* @default false
4582
* Notes:
4683
* - `someClassName` can not be a js key word like `const`, `var` & etc.
4784
* - cannot be used with `inject`
4885
*/
4986
namedExports?: boolean;
87+
/**
88+
* optional package detail
89+
*/
5090
package?: {
5191
name: string;
5292
main?: string;

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-present indooorsman, https://me.csser.top
3+
Copyright (c) 2021-present indooorsman(Chuanye, Wang), https://me.csser.top
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esbuild-css-modules-plugin",
3-
"version": "3.0.0-dev.20",
3+
"version": "3.0.0",
44
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).",
55
"main": "./index.cjs",
66
"module": "./index.js",

readme.md

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
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

66
A esbuild plugin to bundle css modules into js(x)/ts(x).
77

88
Works 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

2020
or
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';
3232
esbuild.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
});

test/app.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22
import ReactDom from 'react-dom';
33
import klass from './styles/app.modules.css';
4+
import klass2 from './styles/app-filter.css';
45

56
import { HelloWorld } from './components/hello.world';
67

78
const App = () => {
89
return (
9-
<div className={klass.helloWorld}>
10+
<div className={`${klass.helloWorld} ${klass2.helloWorld}`}>
1011
<HelloWorld />
1112
</div>
1213
);

test/components/filter.world.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
import * as styles from '../styles/app-filter.css';
3-
import * as styles2 from '../styles/deep/styles/hello-filter.css';
2+
import styles from '../styles/app-filter.css';
3+
import styles2 from '../styles/deep/styles/hello-filter.css';
44

55
export const HelloWorld = () => (
66
<>

test/components/named-exports.world.jsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/named-exports.jsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esbuild-css-modules-plugin-test",
3-
"version": "3.0.0-dev",
3+
"version": "3.0.0",
44
"private": true,
55
"type": "module"
66
}

0 commit comments

Comments
 (0)