Git Advanced: Monorepo, Submodules & Workflows · 강의

모노레포의 종속성 관리

모노레포 내 여러 프로젝트에서 내부 및 외부 종속성을 관리하는 기법을 살펴봅니다.

레슨 1/411개 단계

모노레포의 종속성 관리은(는) CoddyKit의 무료 Git Advanced: Monorepo, Submodules & Workflows 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Git Advanced: Monorepo, Submodules & Workflows 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Git Advanced: Monorepo, Submodules & Workflows 강의에는 총 4개의 강의가 포함되어 있습니다.

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

Monorepo Dependencies Explained

Welcome to dependency management in monorepos! In a monorepo, many projects live together in one Git repository.

This setup brings unique challenges and benefits for how these projects share and rely on code.

  • Internal Dependencies: When one project in the monorepo uses code from another project in the same monorepo.
  • External Dependencies: When projects use third-party libraries or frameworks (like React or Lodash).

Internal Dependencies: Code Sharing

One of the biggest advantages of a monorepo is easy code sharing. Imagine you have a shared UI component library and several applications using it.

Instead of publishing and consuming it as a separate package, you can reference it directly within the monorepo.

This simplifies development, testing, and ensures consistency across your applications.

External Dependencies: Third-Party Libraries

Just like any project, those in a monorepo often rely on external, open-source libraries. Think of popular tools like Node.js packages (e.g., Express, Axios) or Java libraries (e.g., Spring Boot, Guava).

Managing these can be tricky. Different projects might need different versions of the same external library, or you might want to enforce a single version across all projects for consistency.

Package Managers & Workspaces

For languages like JavaScript, package managers such as npm, Yarn, or pnpm are essential. They typically introduce a concept called workspaces.

Workspaces allow you to manage multiple packages within a single root package.json. This enables:

  • Centralized dependency installation.
  • Cross-referencing internal packages easily.
  • Optimized disk space usage.

Workspace Hoisting Explained

A key feature of monorepo package managers is hoisting. Instead of installing the same external dependency multiple times in each project's node_modules folder, it's 'hoisted' to the root node_modules.

This means:

  • Less disk space used.
  • Faster installation times.
  • Ensures all projects use the same version of a hoisted dependency, reducing potential conflicts.

Setting Up npm Workspaces

Let's see how to configure npm workspaces. You define them in the root package.json file.

Here, we tell npm to look for packages in the packages/* directory. Each sub-directory will contain its own package.json.

{
  "name": "my-monorepo",
  "version": "1.0.0",
  "private": true,
  "workspaces": [
    "packages/*"
  ],
  "scripts": {
    "install:all": "npm install"
  }
}

Using Internal & External Dependencies

Now, let's create a simple ui-lib and an app project inside our packages/ folder. The app will depend on ui-lib and an external library, lodash.

Notice how ui-lib is referenced by its package name in app/package.json.

/* packages/ui-lib/package.json */
{
  "name": "ui-lib",
  "version": "1.0.0",
  "main": "index.js"
}

/* packages/ui-lib/index.js */
export const Button = () => 'Monorepo Button';

/* packages/app/package.json */
{
  "name": "app",
  "version": "1.0.0",
  "dependencies": {
    "ui-lib": "*",
    "lodash": "^4.17.21"
  }
}

/* packages/app/index.js */
import { Button } from 'ui-lib';
import { capitalize } from 'lodash';

console.log(capitalize(Button()));
// Run 'npm install' from root, then 'node packages/app/index.js'

Managing Version Conflicts

What if one project needs lodash@3.x and another needs lodash@4.x?

Monorepo tools often try to hoist a single version. If different versions are specified, some package managers might install multiple versions or require explicit overrides.

Best practice: Aim for a single, consistent version of major external dependencies across the entire monorepo to avoid complex resolution issues and ensure compatibility.

Dependency Graph & Tools

As monorepos grow, understanding the relationships between projects becomes crucial. A dependency graph visually maps out which projects depend on which.

Tools like Nx, Lerna, and Turborepo generate these graphs, helping you:

  • Identify critical paths.
  • Understand the impact of changes.
  • Optimize build processes by only rebuilding affected projects.

Quick Check: Monorepo Dependencies

Consider a monorepo using npm workspaces with multiple projects. Which of the following statements about dependency management are true?

Recap: Monorepo Dependency Mastery

You've learned the essentials of dependency management in monorepos!

  • Internal dependencies foster code sharing and consistency.
  • External dependencies are managed efficiently using workspace features.
  • Workspaces and hoisting optimize installation, disk space, and version consistency.
  • Understanding the dependency graph is key for large monorepos.

Mastering these techniques is vital for building scalable and maintainable monorepo projects.

무료로 시작

AI 튜터와 함께 Git Advanced: Monorepo, Submodules & Workflows을(를) 배우세요 — 무료

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

코스
12
레슨
48

자주 묻는 질문

“모노레포의 종속성 관리” 강의는 무료인가요?

네 — “모노레포의 종속성 관리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Git Advanced: Monorepo, Submodules & Workflows 강의 전체를 잠금 해제할 수 있습니다. Git Advanced: Monorepo, Submodules & Workflows 강의에는 총 4개의 강의가 포함되어 있습니다.

“모노레포의 종속성 관리”에서 뭘 배우나요?

모노레포 내 여러 프로젝트에서 내부 및 외부 종속성을 관리하는 기법을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 Git Advanced: Monorepo, Submodules & Workflows을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Git Advanced: Monorepo, Submodules & Workflows을(를) 시작하는 데 경험이 필요한가요?

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

“모노레포의 종속성 관리” 강의는 얼마나 걸리나요?

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

이 Git Advanced: Monorepo, Submodules & Workflows 강의에서 코드를 작성하고 실행할 수 있나요?

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

이 강의의 모든 강의

  1. 모노레포의 종속성 관리
  2. 원자적 커밋 및 프로젝트 간 변경
  3. 모노레포 CI/CD 전략
  4. 빌드 캐싱 및 변경된 항목만 빌드하기
← Git Advanced: Monorepo, Submodules & Workflows(으)로 돌아가기