You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/loader.md
+61-1Lines changed: 61 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Loader hook (`?knighted-css`)
1
+
# Loader hook
2
2
3
3
`@knighted/css/loader` lets bundlers attach compiled CSS strings to any module by appending the `?knighted-css` query when importing. The loader mirrors the module graph, compiles every CSS dialect it discovers (CSS, Sass, Less, vanilla-extract, etc.), and exposes the concatenated result as `knightedCss`.
4
4
@@ -34,6 +34,66 @@ export default {
34
34
}
35
35
```
36
36
37
+
### Choosing a type generation mode
38
+
39
+
`knighted-css-generate-types` supports two modes. Both are fully supported and tested; the right choice depends on how explicit you want the imports to be versus how much resolver automation you want to lean on:
40
+
41
+
-`--mode module` (double-extension imports): use `.knighted-css` sidecar modules such as
42
+
`import stableSelectors from './button.css.knighted-css.js'`. This keeps resolution explicit and tends to be the most stable under large, complex builds.
43
+
-`--mode declaration` (idiomatic imports): emit `.d.ts` sidecars next to the original JS/TS module
44
+
and keep clean imports like `import { knightedCss } from './button.js'`. This is cleaner at call sites, but it adds resolver work at build time and depends on the resolver plugin to stay in sync.
45
+
46
+
If you want the simplest, most transparent build behavior, start with `--mode module`.
47
+
If you want cleaner imports and are comfortable with resolver automation, choose `--mode declaration` and enable strict sidecars + a manifest for safety.
48
+
49
+
### Resolver plugin (declaration mode)
50
+
51
+
When you use `knighted-css-generate-types --mode declaration`, TypeScript expects the
52
+
augmented exports to be present on the original JS/TS module. Use the resolver plugin
53
+
to automatically append `?knighted-css` for any module import that has a generated
> The loader shares the same auto-configured `oxc-resolver` as the standalone `css()` API, so hash-prefixed specifiers declared under `package.json#imports` (for example, `#ui/button`) resolve without additional options.
Copy file name to clipboardExpand all lines: docs/type-generation.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,17 @@ Wire it into `postinstall` or your build so new selectors land automatically.
29
29
-`--auto-stable` – enable auto-stable selector generation during extraction (mirrors the loader’s auto-stable behavior).
30
30
-`--hashed` – emit proxy modules that export `selectors` backed by loader-bridge hashed class names (mutually exclusive with `--auto-stable`).
31
31
-`--resolver` – path or package name exporting a `CssResolver` (default export or named `resolver`).
32
+
-`--mode` – `module` (default) emits `.knighted-css.ts` proxy modules. `declaration` emits `.d.ts` module augmentations next to the referenced JS/TS modules, so you can keep standard imports like `import { knightedCss } from './button.js'` while the generator still discovers them via `.knighted-css` specifiers.
33
+
-`--manifest` – optional path to write a sidecar manifest for declaration mode (recommended when you want strict resolver behavior).
34
+
35
+
### Mode quick reference
36
+
37
+
| Mode | Import style | Generated files | Bundler resolver plugin | Best for |
|`module` (default) | Double-extension (`.knighted-css`) |`.knighted-css.*` proxy modules | Not required | Maximum transparency and stability in large builds |
40
+
|`declaration`| Plain JS/TS imports |`.d.ts` augmentations next to modules | Required (append `?knighted-css`) | Cleaner imports when you accept resolver overhead |
41
+
42
+
If you use declaration mode, prefer enabling strict sidecars + a manifest so the resolver only rewrites imports that the CLI generated.
Copy file name to clipboardExpand all lines: packages/css/README.md
+49-2Lines changed: 49 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ I needed a single source of truth for UI components that could drop into both li
30
30
- Deterministic selector duplication via `autoStable`: duplicate matching class selectors with a stable namespace (default `knighted-`) in both plain CSS and CSS Modules exports.
31
31
- Pluggable resolver/filter hooks for custom module resolution (e.g., Rspack/Vite/webpack aliases) or selective inclusion.
32
32
- First-class loader (`@knighted/css/loader`) so bundlers can import compiled CSS alongside their modules via `?knighted-css`.
33
-
- Built-in type generation CLI (`knighted-css-generate-types`) that emits `.knighted-css.*` selector manifests so TypeScript gets literal tokens in lockstep with the loader exports.
33
+
- Built-in type generation CLI (`knighted-css-generate-types`) that emits `.knighted-css.*` selector manifests (module mode) or declaration augmentations (declaration mode) so TypeScript stays in lockstep with loader exports.
34
34
35
35
## Requirements
36
36
@@ -107,7 +107,7 @@ See [docs/loader.md](../../docs/loader.md) for the full configuration, combined
If you want the resolver to only match sidecars generated by the CLI, enable strict mode and provide a manifest (written by `knighted-css-generate-types --manifest`):
Copy file name to clipboardExpand all lines: packages/css/package.json
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "@knighted/css",
3
-
"version": "1.1.1",
3
+
"version": "1.2.0-rc.0",
4
4
"description": "A build-time utility that traverses JavaScript/TypeScript module dependency graphs to extract, compile, and optimize all imported CSS into a single, in-memory string.",
0 commit comments