Index of every page on this site: llms.txt
All skills
Run it yourself

Efficiently manage CSS imports in TypeScript codebases, understanding tsc vs esbuild behavior for fast, low-config, maintainable setups.

  • 1 file
  • 4.6 KB
  • Updated 9 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/corey-alix/dwp-hours/inline-css

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈37 tokens for metadata: the name and description. ≈1.1k when used: this file.

Description uses 1.9% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈149 characters, or 1.9%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Agent Skill: Handling CSS Imports in TypeScript Projects (tsc vs esbuild)

Skill Name
css-imports-typescript-esbuild

Description
Efficiently manage import "./styles.css" (and .module.css) in TypeScript codebases.
Understand what tsc does vs modern bundlers (especially esbuild).
Prefer fast, low-config, maintainable setups.

Applicable Versions (as of Feb 2026)

  • TypeScript ≥ 5.0
  • esbuild ≥ 0.20 (behavior stable since ~0.8–0.12)

Core Facts

Tool import "./file.css" allowed? Inlines CSS into JS bundle? Emits separate .css file? Default loader behavior Best Use Case
tsc Yes (with config) Never No (ignores) No emit — only type checking Pure type-checking + declaration emit
esbuild Yes Yes — when bundle: true Yes — when no JS entry .css → CSS → inject <style> or separate file Most modern apps, libs, SSR front-ends

tsc — Type-Only Support (2025–2026 standard)

Enable arbitrary non-JS imports without errors:

// tsconfig.json
{
  "compilerOptions": {
    "moduleResolution": "bundler",
    "module": "preserve", // or "esnext"
    "allowArbitraryExtensions": true,
    "noEmit": true, // common with esbuild/vite
    "isolatedModules": true,
  },
}

Optional — explicit module declaration for CSS Modules:

```ts
// src/styles.d.css.ts  (or global.d.ts)
declare module "*.css" {
  const classes: Record<string, string>;
  export default classes;
}

declare module "*.module.css" {
  const classes: Record<string, string>;
  export default classes;
}
```

→ `tsc` never emits CSS or JS code for it.
→ Use with esbuild / vite / rollup for actual bundling.

**esbuild — Recommended Default (fast & clean)**

Built-in CSS handling — no plugins needed in 99% of cases.

```js
// build.js (ESM)
import esbuild from "esbuild";

await esbuild.build({
  entryPoints: ["src/index.tsx"],
  bundle: true,
  minify: true,
  format: "esm",
  platform: "browser",
  outfile: "dist/app.js",
  // loader: { '.css': 'css' }          // default — usually not needed
  // or { '.module.css': 'local-css' }  // for CSS modules (exports object)
});
```

**Behavior Matrix (esbuild bundle: true)**

| Import style                            | Loader (default) | Result in browser bundle                    | Export value (if imported) |
| --------------------------------------- | ---------------- | ------------------------------------------- | -------------------------- |
| `import "./global.css"`                 | `css`            | Injects `<style>` tag at runtime            | `undefined` / void         |
| `import styles from "./mod.module.css"` | `local-css`      | Injects `<style>`, exports hashed class map | `{ [className]: string }`  |
| `import raw from "./file.css?raw"`      | `text` (manual)  | `raw` = string containing CSS               | `string`                   |

**Patterns – Pick One per Project**

1. **Browser SPA (Vite / esbuild dev + build)**
   → `import "./App.css"` → auto-injected styles
   → Use `local-css` for modules

2. **Library / Component (emits JS + separate CSS)**
   → `--bundle --splitting` + external CSS handling
   → Or emit CSS separately: `esbuild --entryPoints=src/index.ts src/index.css --outdir=dist`

3. **SSR / full inline (rare)**
   → Use plugin or custom loader → collect CSS strings
   → esbuild alone does **not** inline to JS string by default (unlike style-loader)

**Quick Checklist (Maintainable Setup)**

- [ ] `tsconfig.json`: `allowArbitraryExtensions`, `moduleResolution: "bundler"`
- [ ] Use esbuild (or Vite) — never rely on `tsc` for CSS emit
- [ ] Decide early: global CSS vs modules vs CSS-in-JS
- [ ] Avoid custom plugins unless you need PostCSS / Sass transforms
- [ ] Test: `import classes from "./Button.module.css"; classes.primary` → autocompletes & typesafe

**Verdict**
**tsc** → types only, no inlining, no emission
**esbuild** → inlines/injects CSS automatically when bundling → fastest path for most projects in 2026

Use this skill when: onboarding new TS+CSS repo, debugging "CSS not applying", choosing bundler.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at e4fbc1d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Dormantupdated 9 months ago

README badge

README badge for corey-alix/dwp-hours/inline-css