#1 dnd-core 프로젝트 생성 및 준비

Leo·2022년 4월 19일
0

OpenSourse-ReactDnD

목록 보기
2/3

내용


오픈소스 React DnD 패키지의 dnd-core 패키지를 분석

react dnd 패키지 생성

git clone https://github.com/algo2000/react-dnd-package.git

전역 Base tsconfig & gitignore

.gitignore

node_modules/

tsconfig.base.json

{
  "extends": "@tsconfig/strictest",
  "compilerOptions": {
    "target": "ESNext", // 사용할 버전 -> ES6 이후 버전들을 통틀어 ESNext
    "module": "ESNext", // 모듈을 위한 코드 생성 설정
    "moduleResolution": "Node", // 모듈 해석 방법 설정
    "lib": [  // 컴파일에 포함될 라이브러리 파일 목록
      "ESNext",
      "DOM"
    ],
    "jsx": "react-jsx", // JSX 코드 생성 설정
    "declaration": true, // .d.ts' 파일 생성 여부

		// default export이 아닌 모듈에서도 default import가 가능하게 할 지 여부
    "allowSyntheticDefaultImports": true
  }
}
  • 컴파일 옵션 정리
    {
    	"compilerOptions": {
    	/* https://aka.ms/tsconfig.json 를 방문하면 해당 파일에 대한 더 많은 정보를 얻을 수 있습니다. */
    	// 옵션은 아래와 같은 형식으로 구성되어 있습니다.
    	// "모듈 키": 모듈 값 /* 설명: 사용가능 옵션 (설명이 "~ 여부"인 경우 'true', 'false') */
    	/* 기본 옵션 */
    	// "incremental": true, /* 증분 컴파일 설정 여부 */
    	"target": "es5", /* 사용할 특정 ECMAScript 버전 설정: 'ES3' (기본), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 혹은 'ESNEXT'. */
    	"module": "commonjs", /* 모듈을 위한 코드 생성 설정: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    	// "lib": [], /* 컴파일에 포함될 라이브러리 파일 목록 */
    	// "allowJs": true, /* 자바스크립트 파일 컴파일 허용 여부 */
    	// "checkJs": true, /* .js 파일의 오류 검사 여부 */
    	// "jsx": "preserve", /* JSX 코드 생성 설정: 'preserve', 'react-native', 혹은 'react'. */
    	// "declaration": true, /* '.d.ts' 파일 생성 여부. */
    	// "declarationMap": true, /* 각 '.d.ts' 파일의 소스맵 생성 여부. */
    	// "sourceMap": true, /* '.map' 파일 생성 여부. */
    	// "outFile": "./", /* 단일 파일로 합쳐서 출력합니다. */
    	// "outDir": "./", /* 해당 디렉토리로 결과 구조를 보냅니다. */
    	// "rootDir": "./", /* 입력 파일의 루트 디렉토리(rootDir) 설정으로 --outDir로 결과 디렉토리 구조를 조작할 때 사용됩니다. */
    	// "composite": true, /* 프로젝트 컴파일 여부 */
    	// "tsBuildInfoFile": "./", /* 증분 컴파일 정보를 저장할 파일 */
    	// "removeComments": true, /* 주석 삭제 여부 */
    	// "noEmit": true, /* 결과 파일 내보낼지 여부 */
    	// "importHelpers": true, /* 'tslib'에서 헬퍼를 가져올 지 여부 */
    	// "downlevelIteration": true, /* 타겟이 'ES5', 'ES3'일 때에도 'for-of', spread 그리고 destructuring 문법 모두 지원 */
    	// "isolatedModules": true, /* 각 파일을 분리된 모듈로 트랜스파일 ('ts.transpileModule'과 비슷합니다). */
    	/* 엄격한 타입-확인 옵션 */
    	"strict": true, /* 모든 엄격한 타입-체킹 옵션 활성화 여부 */
    	// "noImplicitAny": true, /* 'any' 타입으로 구현된 표현식 혹은 정의 에러처리 여부 */
    	// "strictNullChecks": true, /* 엄격한 null 확인 여부 */
    	// "strictFunctionTypes": true, /* 함수 타입에 대한 엄격한 확인 여부 */
    	// "strictBindCallApply": true, /* 함수에 엄격한 'bind', 'call' 그리고 'apply' 메소드 사용 여부 */
    	// "strictPropertyInitialization": true, /* 클래스의 값 초기화에 엄격한 확인 여부 */
    	// "noImplicitThis": true, /* 'any' 타입으로 구현된 'this' 표현식 에러처리 여부 */
    	// "alwaysStrict": true, /* strict mode로 분석하고 모든 소스 파일에 "use strict"를 추가할 지 여부 */
    	/* 추가적인 확인 */
    	// "noUnusedLocals": true, /* 사용되지 않은 지역 변수에 대한 에러보고 여부 */
    	// "noUnusedParameters": true, /* 사용되지 않은 파라미터에 대한 에러보고 여부 */
    	// "noImplicitReturns": true, /* 함수에서 코드의 모든 경로가 값을 반환하지 않을 시 에러보고 여부 */
    	// "noFallthroughCasesInSwitch": true, /* switch문에서 fallthrough 케이스에 대한 에러보고 여부 */
    	/* 모듈 해석 옵션 */
    	// "moduleResolution": "node", /* 모듈 해석 방법 설정: 'node' (Node.js) 혹은 'classic' (TypeScript pre-1.6). */
    	// "baseUrl": "./", /* non-absolute한 모듈 이름을 처리할 기준 디렉토리 */
    	// "paths": {}, /* 'baseUrl'를 기준으로 불러올 모듈의 위치를 재지정하는 엔트리 시리즈 */
    	// "rootDirs": [], /* 결합된 컨텐츠가 런타임에서의 프로젝트 구조를 나타내는 루트 폴더들의 목록 */
    	// "typeRoots": [], /* 타입 정의를 포함할 폴더 목록, 설정 안 할 시 기본적으로 ./node_modules/@types로 설정 */
    	// "types": [], /* 컴파일중 포함될 타입 정의 파일 목록 */
    	// "allowSyntheticDefaultImports": true, /* default export이 아닌 모듈에서도 default import가 가능하게 할 지 여부, 해당 설정은 코드 추출에 영향은 주지 않고, 타입확인에만 영향을 줍니다. */
    	"esModuleInterop": true, /* 모든 imports에 대한 namespace 생성을 통해 CommonJS와 ES Modules 간의 상호 운용성이 생기게할 지 여부, 'allowSyntheticDefaultImports'를 암시적으로 승인합니다. */
    	// "preserveSymlinks": true, /* symlik의 실제 경로를 처리하지 않을 지 여부 */
    	// "allowUmdGlobalAccess": true, /* UMD 전역을 모듈에서 접근할 수 있는 지 여부 */
    	/* 소스 맵 옵션 */
    	// "sourceRoot": "", /* 소스 위치 대신 디버거가 알아야 할 TypeScript 파일이 위치할 곳 */
    	// "mapRoot": "", /* 생성된 위치 대신 디버거가 알아야 할 맵 파일이 위치할 곳 */
    	// "inlineSourceMap": true, /* 분리된 파일을 가지고 있는 대신, 단일 파일을 소스 맵과 가지고 있을 지 여부 */
    	// "inlineSources": true, /* 소스맵과 나란히 소스를 단일 파일로 내보낼 지 여부, '--inlineSourceMap' 혹은 '--sourceMap'가 설정되어 있어야 한다. */
    	/* 실험적 옵션 */
    	// "experimentalDecorators": true, /* ES7의 decorators에 대한 실험적 지원 여부 */
    	// "emitDecoratorMetadata": true, /* decorator를 위한 타입 메타데이터를 내보내는 것에 대한 실험적 지원 여부 */
    	/* 추가적 옵션 */
    	"skipLibCheck": true, /* 정의 파일의 타입 확인을 건너 뛸 지 여부 */
    	"forceConsistentCasingInFileNames": true /* 같은 파일에 대한 일관되지 않은 참조를 허용하지 않을 지 여부 */
    	}
    }
    
    출처: https://geonlee.tistory.com/214 [빠리의 택시 운전사]

dnd-core 폴더 구성

dnd-core 폴더 내에 구성

프로젝트 Config 파일 구성

package.json 생성

npm init

typescript 패키지 설치

typescript 활용을 위해 설치

// 개발 및 테스트 전용 패키지
npm i typescript --save-dev

swc 패키지 설치

Rust로 작성된 ts/js 컴파일러 매우빠름

@swc/core

npm i @swc/cli --save-dev
npm i @swc/core --save-dev

npm-run-all 패키지 설치

package.json의 script 여러개를 실행시키기 위한 패키지 이다. 빌드 과정 즉 개발 과정에서만 필요하므로 dev 로 설치한다.

npm i npm-run-all --save-dev

shx 패키지 설치

shx ShellJS Unix 명령에 대한 래퍼, npm 패키지 스크립트에서 간단한 Unix와 유사한 플랫폼 간 명령 제공

npm i shx --save-dev

Redux 패키지 설치

DnD의 상태 관리를 위해 필요합니다.

npm i redux

package.json 구성

{
  "name": "dnd-core",
  "version": "0.0.1",
  "description": "react dnd => dnd-core package",
  "type": "module",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "clean": "shx rm -rf dist/",
    "build_types": "tsc -b .",
    "build_esm": "swc -C module.type=es6 -d dist src/",
    "build": "run-s build_types build_esm"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/algo2000/react-dnd-package.git"
  },
  "dependencies": {
    "redux": "^4.2.0"
  },
  "devDependencies": {
    "@swc/cli": "^0.1.57",
    "@swc/core": "^1.2.165",
    "npm-run-all": "^4.1.5",
    "shx": "^0.3.4",
    "typescript": "^4.6.3"
  }
}

tsconfig.json 구성

{
  "extends": "../tsconfig.base.json",
  "compilerOptions": {
    "baseUrl": "./src", // non-absolute한 모듈 이름을 처리할 기준 디렉토리
    "emitDeclarationOnly": true, //'.d.ts' 선언 파일만 내보냄
    "outDir": "dist"  // 해당 디렉토리로 결과 구조를 보냅니다
  },
  "include": [
    "./src/index.ts"
  ]
}

정리


Git Commit History


https://github.com/algo2000/react-dnd-package/commit/0d99332b78c69816b3ff85f2c0feed3caa7892b3

노션 링크


dnd-core #1

Reference


[Node.js] npm 패키지 사용법

@swc/core

[Git] .gitignore 파일 생성 방법

tsconfig.json 컴파일 옵션 정리

profile
개발자

0개의 댓글