|
| 1 | +# Knighted CSS Combined Loader Reference |
| 2 | + |
| 3 | +This document summarizes how `?knighted-css&combined` behaves for different module export shapes and how to structure your imports accordingly. Use it as guidance when filing documentation feedback for `@knighted/css`. |
| 4 | + |
| 5 | +## Decision Matrix |
| 6 | + |
| 7 | +| Source module exports | Recommended query | TypeScript import pattern | Notes | |
| 8 | +| --------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | |
| 9 | +| **Named exports only** | `?knighted-css&combined&named-only` | [Snippet](#named-exports-only) | `&named-only` disables the synthetic default export so you only destructure the original named members plus `knightedCss`. | |
| 10 | +| **Default export only** | `?knighted-css&combined` | [Snippet](#default-export-only) | Loader mirrors the default export and adds `knightedCss`, so default-import code keeps working. | |
| 11 | +| **Default + named exports** | `?knighted-css&combined` (append `&named-only` when you never consume the default) | [Snippet](#default-and-named-exports) | Without the flag you get both default + named exports; adding it drops the synthetic default for stricter codebases. | |
| 12 | + |
| 13 | +## Named exports only |
| 14 | + |
| 15 | +```ts |
| 16 | +import type { KnightedCssCombinedModule } from '@knighted/css/loader' |
| 17 | +import combined from './module.js?knighted-css&combined&named-only' |
| 18 | + |
| 19 | +const { Component, knightedCss } = combined as KnightedCssCombinedModule< |
| 20 | + typeof import('./module.js') |
| 21 | +> |
| 22 | +``` |
| 23 | + |
| 24 | +> [!NOTE] |
| 25 | +> Namespace imports (`import * as combined …`) are the most reliable pattern for `&named-only` queries because you intentionally drop the default export. Keep using the helper type to narrow the namespace. |
| 26 | +
|
| 27 | +## Default export only |
| 28 | + |
| 29 | +```ts |
| 30 | +import type { KnightedCssCombinedModule } from '@knighted/css/loader' |
| 31 | +import combined from './module.js?knighted-css&combined' |
| 32 | + |
| 33 | +const { default: Component, knightedCss } = combined as KnightedCssCombinedModule< |
| 34 | + typeof import('./module.js') |
| 35 | +> |
| 36 | +``` |
| 37 | + |
| 38 | +## Default and named exports |
| 39 | + |
| 40 | +```ts |
| 41 | +import type { KnightedCssCombinedModule } from '@knighted/css/loader' |
| 42 | +import combined from './module.js?knighted-css&combined' |
| 43 | + |
| 44 | +const { |
| 45 | + default: Component, |
| 46 | + helper, |
| 47 | + knightedCss, |
| 48 | +} = combined as KnightedCssCombinedModule<typeof import('./module.js')> |
| 49 | +``` |
| 50 | + |
| 51 | +Prefer `?knighted-css&combined&named-only` plus the [named exports only](#named-exports-only) snippet when you intentionally avoid default exports but still need the named members and `knightedCss`. |
| 52 | + |
| 53 | +## Key Takeaways |
| 54 | + |
| 55 | +- The loader always injects `knightedCss` alongside the module’s exports. |
| 56 | +- To avoid synthetic defaults (and TypeScript warnings) for modules that only expose named exports, add `&named-only` and use a namespace import. |
| 57 | +- Namespace imports plus `KnightedCssCombinedModule<typeof import('./module')>` work universally; default imports are optional conveniences when the source module exposes a default you actually consume. |
0 commit comments