NX의 파일 구조와 설정 파일들의 역할을 상세히 설명하겠습니다.
my-nx-workspace/
├── apps/ # 애플리케이션들이 위치
│ ├── app1/
│ │ ├── src/
│ │ ├── project.json # 앱별 빌드 설정
│ │ └── tsconfig.json # 앱별 TypeScript 설정
├── libs/ # 공유 라이브러리들이 위치
│ ├── lib1/
│ │ ├── src/
│ │ ├── project.json
│ │ └── tsconfig.json
├── tools/ # 커스텀 스크립트, 도구들
├── nx.json # NX 워크스페이스 설정
├── package.json
└── tsconfig.base.json # 기본 TypeScript 설정
A. package.json
{
"name": "my-nx-workspace",
"version": "0.0.0",
"scripts": {
"start": "nx serve",
"build": "nx build",
"test": "nx test"
},
"dependencies": {
"@nx/angular": "^latest",
"@nx/nest": "^latest"
}
}
B. nx.json
{
"npmScope": "my-org",
"affected": {
"defaultBase": "main"
},
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "test", "lint"]
}
}
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
}
}
}
C. tsconfig.base.json
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@my-org/lib1": ["libs/lib1/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
}
D. apps/[app-name]/tsconfig.json
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/apps/[app-name]",
"types": ["node", "jest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
}
]
}
E. apps/[app-name]/tsconfig.app.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/apps/[app-name]",
"module": "commonjs",
"types": ["node"]
},
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
F. apps/[app-name]/project.json
{
"name": "app-name",
"projectType": "application",
"sourceRoot": "apps/app-name/src",
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/app-name",
"main": "apps/app-name/src/main.ts",
"tsConfig": "apps/app-name/tsconfig.app.json"
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true
},
"development": {
"optimization": false,
"extractLicenses": false
}
}
},
"serve": {
"executor": "@nx/webpack:dev-server",
"options": {
"buildTarget": "app-name:build"
}
}
}
}
1) 프로젝트 초기화 시:
2) 앱 빌드/실행 시:
nx serve my-app 실행 →
↓
project.json 로드 (빌드 설정 확인)
↓
tsconfig.json 로드 (기본 설정)
↓
tsconfig.app.json 로드 (빌드별 설정)
↓
tsconfig.base.json 참조 (공통 설정)
↓
빌드 프로세스 시작
3) 라이브러리 참조 시:
4) 개발 서버 실행 시:
5) 프로덕션 빌드 시:
이러한 구조와 설정들은 모듈성, 재사용성, 확장성을 극대화하면서도 일관된 개발 환경을 제공하는 것이 목적입니다.