Skip to content

A build-time utility that traverses module dependency graphs to extract, compile, and optimize all imported CSS into a single, in-memory string.

Notifications You must be signed in to change notification settings

knightedcodemonkey/css

Repository files navigation

CI codecov NPM version

@knighted/css is a zero-bundler CSS pipeline for JavaScript and TypeScript projects. Point it at an entry module and it walks the graph, compiles every CSS-like dependency (CSS, Sass/SCSS, Less, vanilla-extract), and hands back both a concatenated stylesheet string and optional .knighted-css.* selector manifests for type-safe loaders.

What it does (at a glance)

  • Graph walking: Follows import trees the same way Node does (tsconfig paths, package exports/imports, hash specifiers, etc.) using oxc-resolver.
  • Multi-dialect compilation: Runs Sass, Less, Lightning CSS, or vanilla-extract integrations on demand so every dependency ends up as plain CSS.
  • Loader + CLI: Ship CSS at runtime via ?knighted-css loader queries or ahead of time via the css() API and the knighted-css-generate-types command.
  • Shadow DOM + SSR ready: Inline styles in server renders, ship them alongside web components, or keep classic DOM apps in sync—all without wiring a full bundler.

See the docs/ directory for deep dives on loaders, type generation, specificity boosts, Sass aliases, the combined import queries, and the current 2026 roadmap.

Workspaces in this repo

Workspace NPM Name What it contains
packages/css @knighted/css The production library: graph walker, compilation pipeline, loader helpers, CLI, and docs. Published to npm and meant for real builds.
packages/playwright @knighted/css-playwright-fixture The end-to-end demo + regression suite. Playwright drives Lit + React examples, hash-import workspace scenarios, and SSR checks to ensure the core package keeps working across bundlers.

Each workspace is a standalone npm project. Run commands from the repo root with npm run <script> -w <workspace> or npm run <script> --workspaces to fan out when needed.

Quick start

import { css } from '@knighted/css'

const sheet = await css('./src/entry.tsx', {
  cwd: process.cwd(),
  lightningcss: { minify: true },
})

console.log(sheet) // use during SSR, static builds, or to inline Shadow DOM styles

Contributing & Support

  1. Install deps with npm install.
  2. Run npm run build to compile @knighted/css.
  3. Use npm run test for unit coverage and npm run test:e2e for the Playwright matrix.

Issues and feature ideas are always welcome via GitHub issues.

License

MIT © Knighted Code Monkey

About

A build-time utility that traverses module dependency graphs to extract, compile, and optimize all imported CSS into a single, in-memory string.

Topics

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published