0Pricing
Tailwind CSS Academy · 강의

파일 및 폴더 구성

프로젝트가 단일 파일을 넘어 성장하더라도 CSS 진입점, 컴포넌트 스타일시트, 설정 파일을 명확하게 구성합니다.

파일 및 폴더 구성은(는) CoddyKit의 무료 Tailwind CSS Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Tailwind CSS Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why File Organization Matters

As Tailwind projects grow, the number of files involving CSS-related configuration — the Tailwind config, PostCSS config, global stylesheets, and component-level CSS — multiplies. Without a clear structure, these files scatter across the project and become hard to find. Good file organization makes it immediately obvious where to add new values, where global overrides live, and which CSS belongs to which component.

Root-Level Config Files

Config files that affect the entire build — tailwind.config.js, postcss.config.js, and .prettierrc — live at the project root alongside package.json. They are root-level because build tools discover them by convention. Never nest them inside src/ unless your toolchain explicitly supports non-root config discovery.

my-project/
├── tailwind.config.js      # ← root level
├── postcss.config.js       # ← root level
├── .prettierrc             # ← root level
├── package.json
├── src/
│   ├── styles/
│   │   └── globals.css     # @tailwind directives
│   └── components/

The Styles Directory

Place all CSS files inside a dedicated src/styles/ directory. The main entry point is globals.css, which contains the three @tailwind directives, @layer overrides for base elements, and imports for any additional stylesheets. Component-specific CSS goes in separate files like button.css or prose-overrides.css, imported into globals.css.

src/styles/
├── globals.css           # main entry: @tailwind base/components/utilities
├── base.css              # @layer base: html, body, heading resets
├── components.css        # @layer components: .btn, .card, .badge
├── utilities.css         # @layer utilities: custom utility helpers
└── prose-overrides.css   # @tailwindcss/typography customizations

Anatomy of globals.css

The globals.css file is the entry point imported into your application's root. It declares the three Tailwind directives in order, then imports any additional stylesheets. Avoid putting custom styles directly in this file beyond the directives — keep custom layer declarations in their own files that are imported here for clarity.

/* src/styles/globals.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* Import custom layer files */
@import './base.css';
@import './components.css';
@import './utilities.css';

Co-Locating Component CSS

For component-based frameworks like React or Vue, you can co-locate a small CSS file alongside the component file when the styles are tightly coupled. However, in Tailwind projects this is rare since most styling lives in class names directly in the markup. Reserve co-located CSS only for styles that genuinely cannot be expressed with utilities — such as complex :focus-within selectors or @keyframes.

src/components/
├── Button/
│   ├── Button.tsx
│   └── Button.module.css   # Only if truly needed beyond Tailwind
├── Card/
│   ├── Card.tsx
│   └── Card.test.tsx
└── Modal/
    └── Modal.tsx           # No CSS file — pure Tailwind utilities

Separating Theme Extensions

When the tailwind.config.js grows large, extract the theme.extend object into a separate file like theme/extend.js. This keeps the root config file short and readable, while the theme extension file can grow as long as needed. Import and spread the extension back in the main config.

// theme/extend.js
module.exports = {
  colors: {
    brand: { 50: '#eff6ff', 500: '#3b82f6', 900: '#1e3a8a' },
  },
  fontFamily: {
    display: ['Inter', 'sans-serif'],
  },
  spacing: {
    18: '4.5rem',
    128: '32rem',
  },
};

// tailwind.config.js
const themeExtend = require('./theme/extend');
module.exports = {
  content: [...],
  theme: { extend: themeExtend },
  plugins: [...],
};

Separating Plugin Configuration

If your project uses several Tailwind plugins and each requires significant configuration, extract plugin setups into their own files inside a plugins/ directory. Each file exports a configured plugin and is imported in the main config's plugins array. This makes it easy to see which plugins are active and to adjust their settings independently.

plugins/
├── typography.js     # require('@tailwindcss/typography')({...})
├── forms.js          # require('@tailwindcss/forms')({strategy:'class'})
└── custom-utils.js   # custom plugin function

// tailwind.config.js
module.exports = {
  plugins: [
    require('./plugins/typography'),
    require('./plugins/forms'),
    require('./plugins/custom-utils'),
  ],
};

Organizing Token Files

Design tokens — colors, typography, spacing — are best defined in a separate tokens/ directory rather than inline in the Tailwind config. Each category of tokens lives in its own file: tokens/colors.js, tokens/typography.js, tokens/spacing.js. These files can be shared with design tools, Storybook configurations, and the Tailwind config simultaneously.

tokens/
├── colors.js      # { primary: '#3b82f6', surface: '#ffffff', ... }
├── typography.js  # { fontFamily: { sans: ['Inter', ...] }, ... }
└── spacing.js     # { 18: '4.5rem', 128: '32rem', ... }

// tailwind.config.js
const colors = require('./tokens/colors');
const typography = require('./tokens/typography');
module.exports = {
  theme: {
    extend: { colors, ...typography },
  },
};

Content Glob Patterns

Keep content glob patterns organized and readable. Group them by file type and location rather than writing one catch-all glob that scans too broadly. Comment each glob to explain which part of the project it covers. Maintain this list actively — remove old patterns when directories are renamed or removed, and add new patterns when new file types are introduced.

// tailwind.config.js
content: [
  // Pages and layouts
  './src/pages/**/*.{js,ts,jsx,tsx}',
  './src/layouts/**/*.{js,ts,jsx,tsx}',

  // UI components
  './src/components/**/*.{js,ts,jsx,tsx}',

  // Public HTML files
  './public/**/*.html',

  // Email templates (if any)
  './emails/**/*.{js,ts,jsx,tsx}',
],

Naming Conventions for CSS Layers

When using @layer to add custom styles, follow a consistent naming approach. Use @layer base for element-level resets (e.g., a, h1, input), @layer components for multi-utility patterns with meaningful names (.btn, .card), and @layer utilities for single-purpose utilities not in Tailwind's default set. Never mix these responsibilities.

/* src/styles/base.css */
@layer base {
  html { @apply scroll-smooth; }
  h1 { @apply text-4xl font-extrabold; }
  a { @apply text-blue-600 hover:text-blue-700; }
}

/* src/styles/components.css */
@layer components {
  .btn { @apply rounded-lg px-4 py-2 font-semibold; }
}

/* src/styles/utilities.css */
@layer utilities {
  .text-balance { text-wrap: balance; }
}

README for Style Conventions

Document the file and folder structure in your project's README or a dedicated STYLE_GUIDE.md. Include a diagram of the src/styles/ directory, explain which file each kind of style goes in, and note the content glob maintenance responsibility. New developers should be able to understand where to add a new custom color or a new component class by reading a single page of documentation.

# CSS Architecture

## File Map
- `tailwind.config.js` — theme tokens, content globs, plugins
- `src/styles/globals.css` — entry point, @tailwind directives
- `src/styles/base.css` — element resets in @layer base
- `src/styles/components.css` — .btn, .card, .badge in @layer components
- `tokens/colors.js` — brand color palette

## Adding a new custom utility
Add to `src/styles/utilities.css` inside `@layer utilities { }`. 

Quick Check

Test your understanding of Tailwind CSS Mastery concepts from this lesson.

Lesson Recap

In this lesson you learned: keeping config files at the project root for toolchain compatibility, organizing styles into a src/styles/ directory with separate files per layer, and extracting theme tokens and plugins into dedicated files as the config grows. Next up we explore coexisting with legacy CSS in existing projects.

자주 묻는 질문

“파일 및 폴더 구성” 강의는 무료인가요?

네 — “파일 및 폴더 구성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Tailwind CSS Academy 강의 전체를 잠금 해제할 수 있습니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“파일 및 폴더 구성”에서 뭘 배우나요?

프로젝트가 단일 파일을 넘어 성장하더라도 CSS 진입점, 컴포넌트 스타일시트, 설정 파일을 명확하게 구성합니다. 브라우저에서 직접 실행하는 실습 코드로 Tailwind CSS Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Tailwind CSS Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Tailwind CSS Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“파일 및 폴더 구성” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Tailwind CSS Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Tailwind CSS Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 파일 및 폴더 구성
  2. 레거시 CSS와 함께 사용하기
  3. CSS Modules와 Tailwind
  4. 모노레포 전반으로 Tailwind 확장하기
← Tailwind CSS Academy(으)로 돌아가기