Design Systems & Component Libraries · 강의

패키지 관리 (NPM/Yarn)

업계 표준 패키지 관리자를 사용하여 구성 요소 라이브러리를 게시하고 사용하며 버전을 관리하는 방법을 배웁니다.

레슨 2/411개 단계

패키지 관리 (NPM/Yarn)은(는) CoddyKit의 무료 Design Systems & Component Libraries 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Design Systems & Component Libraries 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Design Systems & Component Libraries 강의에는 총 4개의 강의가 포함되어 있습니다.

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

Your Code's Best Friend: Package Managers

Package managers like NPM (Node Package Manager) and Yarn are essential tools in modern software development. They automate the process of finding, installing, updating, and managing external code libraries and dependencies.

Instead of manually downloading files, you simply tell the package manager what you need, and it handles the rest!

Why Design Systems Need Package Managers

Design systems are collections of reusable UI components and guidelines. To truly be 'reusable' across many different projects and teams, these components need to be easily distributable.

Package managers provide the perfect solution:

  • Distribution: Make your component library available to all applications.
  • Consistency: Ensure all projects use approved, consistent versions.
  • Updates: Easily roll out bug fixes or new features to consumers.
  • Dependency Management: Handle your library's own requirements.

NPM & Yarn: The Big Players

In the JavaScript ecosystem, NPM and Yarn are the two dominant package managers. While they share the same goal, they have different command structures and performance characteristics.

  • NPM: The default package manager for Node.js, widely adopted and robust.
  • Yarn: Created by Facebook, often praised for faster installations and improved security features.

Both primarily manage your project's package.json file and the node_modules directory.

Starting Your Component Library Package

To turn your component library into a shareable package, you need a package.json file. This file is the manifest for your project, containing metadata like its name, version, and dependencies.

You can create this file interactively using the following commands:

npm init
# or
yarn init -y

Key Fields in `package.json` for Libraries

For a component library, specific fields in package.json are critical for proper distribution and consumption:

  • name: A unique identifier for your package (e.g., @myorg/design-system).
  • version: The current version, following Semantic Versioning (SemVer).
  • main: Specifies the entry point file for your package (e.g., dist/index.js).
  • files: An array of files or directories to include when your package is published.
  • private: true: Prevents accidental publishing to a public registry.
{
  "name": "@myorg/design-system",
  "version": "1.0.0",
  "main": "dist/index.js",
  "files": [
    "dist"
  ],
  "license": "MIT",
  "private": false
}

Managing Dependencies: Dev, Peer, Optional

Your component library might rely on other packages. package.json allows you to specify different types of dependencies:

  • dependencies: Packages absolutely required for your library to run (e.g., a utility library).
  • devDependencies: Packages only needed during development, testing, or building (e.g., a testing framework, a bundler like Webpack).
  • peerDependencies: Dependencies that your *consumers* are expected to provide (e.g., React if your components are React components). This prevents multiple versions of the same dependency.
{
  "name": "my-component-lib",
  "version": "1.0.0",
  "dependencies": {
    "lodash": "^4.17.21"
  },
  "peerDependencies": {
    "react": ">=16.8.0",
    "react-dom": ">=16.8.0"
  },
  "devDependencies": {
    "webpack": "^5.0.0"
  }
}

Publishing Your Component Library

Once your component library is built and configured (e.g., compiled to dist/index.js), you can publish it. This makes it available for others to install.

You typically publish to a package registry:

  • Public Registries: Like the official npm registry, for open-source or widely shared packages.
  • Private Registries: For internal company design systems, ensuring privacy and control (e.g., GitHub Packages, Azure Artifacts, private npm).

First, log in, then build your library, and finally publish:

npm login
npm run build # Assuming you have a build script
npm publish --access public # Or omit --access public for private

Consuming Your Design System Package

In an application project that needs to use your design system, consuming the published package is simple. You just install it like any other dependency using its name.

Once installed, you can import and use the components:

// app.js
// This file would be in an application project.
// First, install the package via command line:
// npm install @myorg/design-system
// or
// yarn add @myorg/design-system

// Then, import/require components within your code:
const { Button, Card } = require('@myorg/design-system');

function mainApplicationEntry() {
  console.log("Application started!");
  console.log("Successfully imported Button component.");
  console.log("Successfully imported Card component.");
  // In a real application, you would now use these
  // components to build your UI, e.g., render <Button />
}

mainApplicationEntry();

Semantic Versioning (SemVer) Explained

Package managers rely on Semantic Versioning (SemVer), a standard for version numbers like MAJOR.MINOR.PATCH (e.g., 1.2.3). It communicates the nature of changes in each release:

  • MAJOR (1.0.0 -> 2.0.0): Indicates backward-incompatible API changes. Consumers might need to update their code.
  • MINOR (1.0.0 -> 1.1.0): New features added, but backward-compatible. Existing code should still work.
  • PATCH (1.0.0 -> 1.0.1): Backward-compatible bug fixes. No new features, no breaking changes.

Always increment your version number according to SemVer rules before publishing!

Quick Check: Publishing & Consuming

Imagine you have a new application project and you want to start using components from your company's published design system library.

Lesson Summary: Package Management

We've explored how package managers like NPM and Yarn are vital for design systems. They enable you to:

  • Initialize and configure your component library as a package.
  • Manage different types of dependencies (dependencies, devDependencies, peerDependencies) effectively.
  • Publish your library to public or private registries for others to use.
  • Seamlessly consume shared components in applications using simple install commands.
  • Understand and apply Semantic Versioning (SemVer) for clear and predictable updates.

Mastering package management is key to maintaining a scalable, consistent, and easily distributable design system!

무료로 시작

AI 튜터와 함께 Design Systems & Component Libraries을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“패키지 관리 (NPM/Yarn)” 강의는 무료인가요?

네 — “패키지 관리 (NPM/Yarn)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Design Systems & Component Libraries 강의 전체를 잠금 해제할 수 있습니다. Design Systems & Component Libraries 강의에는 총 4개의 강의가 포함되어 있습니다.

“패키지 관리 (NPM/Yarn)”에서 뭘 배우나요?

업계 표준 패키지 관리자를 사용하여 구성 요소 라이브러리를 게시하고 사용하며 버전을 관리하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Design Systems & Component Libraries을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Design Systems & Component Libraries을(를) 시작하는 데 경험이 필요한가요?

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

“패키지 관리 (NPM/Yarn)” 강의는 얼마나 걸리나요?

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

이 Design Systems & Component Libraries 강의에서 코드를 작성하고 실행할 수 있나요?

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

이 강의의 모든 강의

  1. 버전 관리 전략
  2. 패키지 관리 (NPM/Yarn)
  3. 디자인 시스템을 위한 CI/CD
  4. 자동화된 시각적 회귀 테스트
← Design Systems & Component Libraries(으)로 돌아가기