@better-css-modules/esbuild 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -18
- package/dist/index.d.mts +13 -4
- package/dist/index.mjs +61 -3
- package/package.json +26 -9
- package/dist/index.cjs +0 -4
- package/dist/index.d.cts +0 -6
package/README.md
CHANGED
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
# @better-css-modules/esbuild
|
|
2
2
|
|
|
3
|
-
esbuild plugin for better-css-modules.
|
|
3
|
+
esbuild plugin for better-css-modules. It generates the `.d.ts` files for CSS Modules when a build starts, and puts every module in the cascade layer the config names.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
pnpm add -D @better-css-modules/esbuild
|
|
8
|
+
pnpm add -D @better-css-modules/esbuild @better-css-modules/core @better-css-modules/cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
The config file imports `defineConfig` from `@better-css-modules/core`, and the CLI runs `check`. The plugin needs esbuild 0.28.
|
|
12
|
+
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
15
|
```ts
|
|
14
16
|
import esbuild from "esbuild";
|
|
15
17
|
import betterCssModules from "@better-css-modules/esbuild";
|
|
16
18
|
|
|
17
|
-
esbuild.build({
|
|
19
|
+
await esbuild.build({
|
|
20
|
+
entryPoints: ["src/index.tsx"],
|
|
21
|
+
bundle: true,
|
|
22
|
+
outdir: "dist",
|
|
18
23
|
plugins: [betterCssModules()],
|
|
19
24
|
});
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
With a `layer`, esbuild's source map of a module points into the text with the layer wrapped around it, a few lines below where a rule was written.
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
betterCssModules({
|
|
26
|
-
include: ["src/**/*.module.css"],
|
|
27
|
-
exclude: [],
|
|
28
|
-
outDir: "__generated__",
|
|
29
|
-
silent: false,
|
|
30
|
-
});
|
|
31
|
-
```
|
|
29
|
+
## Configuration
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
| --------- | ---------- | ------------------------- | -------------------------------------------- |
|
|
35
|
-
| `include` | `string[]` | `["src/**/*.module.css"]` | Glob patterns for target CSS Modules files |
|
|
36
|
-
| `exclude` | `string[]` | `[]` | Glob patterns to exclude |
|
|
37
|
-
| `outDir` | `string` | `"__generated__"` | Output directory for generated `.d.ts` files |
|
|
38
|
-
| `silent` | `boolean` | `false` | Suppress console output |
|
|
31
|
+
The plugin takes one option, the config file to use, relative to the working directory: `betterCssModules({ config: "apps/web/better-css-modules.config.ts" })`. By default it reads the `better-css-modules.config.*` in the working directory, the same file the CLI reads. The directory of the config file is the project root, and `include`, `outDir` and the search for sources stay inside it, so put the config in a directory that holds the stylesheets and the sources. See the project README for the [Quick Start](https://github.com/k35o/better-css-modules#quick-start), which sets up `tsconfig.json`, the [configuration](https://github.com/k35o/better-css-modules#configuration) and [cascade layers](https://github.com/k35o/better-css-modules#cascade-layers).
|
|
39
32
|
|
|
40
33
|
## License
|
|
41
34
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Plugin } from "esbuild";
|
|
2
|
+
//#region ../unplugin/dist/index.d.mts
|
|
3
3
|
//#region src/index.d.ts
|
|
4
|
-
|
|
4
|
+
interface Options {
|
|
5
|
+
/**
|
|
6
|
+
* Path of the config file, relative to the working directory. By default,
|
|
7
|
+
* the `better-css-modules.config.*` in the working directory.
|
|
8
|
+
*/
|
|
9
|
+
config?: string;
|
|
10
|
+
}
|
|
5
11
|
//#endregion
|
|
6
|
-
|
|
12
|
+
//#region src/index.d.ts
|
|
13
|
+
declare const plugin: (options?: Options) => Plugin;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type Options, plugin as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createUnplugin } from "unplugin";
|
|
2
|
+
import { loadConfig } from "@better-css-modules/core";
|
|
3
|
+
import { createLayerWrapper, createSync, generateAndPrint } from "@better-css-modules/core/internal";
|
|
4
|
+
//#region ../unplugin/dist/index.mjs
|
|
5
|
+
const generations = /* @__PURE__ */ new Map();
|
|
6
|
+
//#endregion
|
|
2
7
|
//#region src/index.ts
|
|
3
|
-
|
|
8
|
+
const plugin = createUnplugin((options = {}, meta) => {
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
let setup;
|
|
11
|
+
const load = async () => {
|
|
12
|
+
const config = await loadConfig({
|
|
13
|
+
cwd,
|
|
14
|
+
config: options.config
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
config,
|
|
18
|
+
sync: createSync(config),
|
|
19
|
+
wrap: createLayerWrapper(config)
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
name: "better-css-modules",
|
|
24
|
+
enforce: "pre",
|
|
25
|
+
async buildStart() {
|
|
26
|
+
const { config } = await (setup = load());
|
|
27
|
+
if (meta.framework !== "vite") {
|
|
28
|
+
await generateAndPrint(config);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const key = JSON.stringify(config);
|
|
32
|
+
if (!generations.has(key)) {
|
|
33
|
+
const generation = generateAndPrint(config);
|
|
34
|
+
generations.set(key, generation);
|
|
35
|
+
generation.catch(() => {
|
|
36
|
+
if (generations.get(key) === generation) generations.delete(key);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
await generations.get(key);
|
|
40
|
+
},
|
|
41
|
+
transform: {
|
|
42
|
+
order: "pre",
|
|
43
|
+
filter: { id: /\.css$/ },
|
|
44
|
+
async handler(code, id) {
|
|
45
|
+
const { wrap } = await (setup ??= load());
|
|
46
|
+
const wrapped = await wrap(code, id, (file) => this.addWatchFile(file));
|
|
47
|
+
if (!wrapped) return;
|
|
48
|
+
return meta.framework === "esbuild" ? wrapped.code : wrapped;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
esbuild: {
|
|
52
|
+
onLoadFilter: /\.css$/,
|
|
53
|
+
loader: "default"
|
|
54
|
+
},
|
|
55
|
+
async watchChange(id) {
|
|
56
|
+
if (meta.framework !== "vite") return;
|
|
57
|
+
generations.clear();
|
|
58
|
+
await (await setup?.catch(() => void 0))?.sync(id);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}).esbuild;
|
|
4
62
|
//#endregion
|
|
5
|
-
export {
|
|
63
|
+
export { plugin as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-css-modules/esbuild",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "esbuild plugin for better-css-modules",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"css-modules",
|
|
7
|
+
"design-tokens",
|
|
8
|
+
"dts",
|
|
9
|
+
"esbuild",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
4
12
|
"license": "MIT",
|
|
5
13
|
"author": "k8o",
|
|
6
14
|
"repository": {
|
|
@@ -12,20 +20,29 @@
|
|
|
12
20
|
"dist"
|
|
13
21
|
],
|
|
14
22
|
"type": "module",
|
|
15
|
-
"main": "./dist/index.
|
|
16
|
-
"module": "./dist/index.mjs",
|
|
23
|
+
"main": "./dist/index.mjs",
|
|
17
24
|
"types": "./dist/index.d.mts",
|
|
18
25
|
"exports": {
|
|
19
26
|
".": {
|
|
20
|
-
"types":
|
|
21
|
-
|
|
22
|
-
"require": "./dist/index.d.cts"
|
|
23
|
-
},
|
|
24
|
-
"import": "./dist/index.mjs",
|
|
25
|
-
"require": "./dist/index.cjs"
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
32
|
+
"unplugin": "3.0.0",
|
|
33
|
+
"@better-css-modules/core": "0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"esbuild": "0.28.2",
|
|
29
37
|
"@better-css-modules/unplugin": "0.1.3"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"esbuild": "^0.28.0"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=24"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
30
47
|
}
|
|
31
48
|
}
|
package/dist/index.cjs
DELETED