css-modules
БесплатноБез исполняемых скриптовНе проверенCSS Modules with Lightning CSS and PostCSS for component-scoped styling. Covers *.module.css patterns, TypeScript integration, Vite configuration, and…
Об этом скилле
CSS Modules
Overview
CSS Modules provide locally-scoped CSS by automatically generating unique class names at build time. This prevents style conflicts and enables true component encapsulation.
When to Use CSS Modules
| Use Case | CSS Modules | Tailwind |
|---|---|---|
| Complex animations | Best | Good |
| Third-party component styling | Best | Harder |
| Legacy CSS migration | Best | Refactor needed |
| Rapid prototyping | Slower | Best |
| Design system utilities | Not ideal | Best |
| Component encapsulation | Best | N/A |
| Team with CSS expertise | Best | Either |
Hybrid Approach: Use both together - Tailwind for utilities, CSS Modules for complex components.
Documentation Index
Vite Integration
| Topic | URL | Description |
|---|---|---|
| CSS Modules in Vite | https://vite.dev/guide/features#css-modules | Vite's built-in support |
| Lightning CSS | https://vite.dev/guide/features#lightning-css | Fast CSS transforms |
| PostCSS | https://vite.dev/guide/features#postcss | PostCSS configuration |
Lightning CSS
| Topic | URL | Description |
|---|---|---|
| Documentation | https://lightningcss.dev/docs.html | Official docs |
| CSS Modules | https://lightningcss.dev/css-modules.html | Module support |
| Transpilation | https://lightningcss.dev/transpilation.html | Browser targeting |
| Bundling | https://lightningcss.dev/bundling.html | CSS bundling |
CSS Modules Spec
| Topic | URL | Description |
|---|---|---|
| CSS Modules | https://github.com/css-modules/css-modules | Specification |
| Composition | https://github.com/css-modules/css-modules#composition | Composing classes |
| Scoping | https://github.com/css-modules/css-modules#naming | Local vs global |
TypeScript Integration
| Topic | URL | Description |
|---|---|---|
| typed-css-modules | https://github.com/Quramy/typed-css-modules | Generate .d.ts files |
| vite-plugin-css-modules-dts | https://github.com/mrcjkb/vite-plugin-css-modules-dts | Vite plugin |
CSS Modules Fundamentals
File Naming Convention
src/
├── components/
│ ├── Button/
│ │ ├── Button.tsx
│ │ ├── Button.module.css # CSS Module
│ │ └── Button.test.tsx
│ └── Card/
│ ├── Card.tsx
│ ├── Card.module.css # CSS Module
│ └── index.ts
Files ending in .module.css are automatically processed as CSS Modules.
Basic Usage
/* Button.module.css */
.button {
padding: 0.5rem 1rem;
border-radius: 0.375rem;
font-weight: 500;
transition: background-color 150ms ease;
}
.primary {
background-color: hsl(221, 83%, 53%);
color: white;
}
.primary:hover {
background-color: hsl(224, 76%, 48%);
}
.secondary {
background-color: hsl(0, 0%, 96%);
color: hsl(0, 0%, 9%);
}
// Button.tsx
import styles from './Button.module.css'
interface ButtonProps {
variant?: 'primary' | 'secondary'
children: React.ReactNode
}
export function Button({ variant = 'primary', children }: ButtonProps) {
return (
<button className={`${styles.button} ${styles[variant]}`}>
{children}
</button>
)
}
Generated Class Names
<!-- Input -->
<button class="${styles.button} ${styles.primary}">
<!-- Output (generated) -->
<button class="Button_button_x7d9f Button_primary_a3k2j">
Local vs Global Scope
/* Local by default */
.button {
/* Generates: Button_button_hash */
}
/* Explicit local */
:local(.button) {
/* Same as above */
}
/* Global (escape hatch) */
:global(.external-library-class) {
/* Kept as-is: .external-library-class */
}
/* Global within local */
.card :global(.markdown-body) {
/* Scoped parent, global child */
}
Composition
composes Keyword
Share styles between classes:
/* base.module.css */
.flexCenter {
display: flex;
align-items: center;
justify-content: center;
}
.interactive {
cursor: pointer;
transition: all 150ms ease;
}
/* Button.module.css */
.button {
composes: flexCenter from './base.module.css';
composes: interactive from './base.module.css';
padding: 0.5rem 1rem;
}
Multiple Compositions
.primaryButton {
composes: button;
composes: primary from './colors.module.css';
composes: rounded from './shapes.module.css';
}
Usage in React
// Composed class automatically includes all composed classes
<button className={styles.primaryButton}>
{/* Renders: Button_primaryButton_x Button_button_y colors_primary_z shapes_rounded_w */}
</button>
Vite Configuration
Lightning CSS (Recommended)
Lightning CSS is 100x faster than PostCSS for transforms:
npm install lightningcss browserslist
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import browserslistToTargets from 'lightningcss/browserslist'
import browserslist from 'browsersli
Установить css-modules в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл css-modules?
CSS Modules with Lightning CSS and PostCSS for component-scoped styling. Covers *.module.css patterns, TypeScript integration, Vite configuration, and composition. Use when building complex animations, styling third-party components, or migrating legacy CSS.
Как установить скилл css-modules?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл css-modules запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic