๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐Ÿ–ฅ dev-ruby

TypeScript๋กœ npm package์— ๋ฐฐํฌํ•˜๊ธฐ | React Custom hook ๋ฐฐํฌ ๋ณธ๋ฌธ

์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

TypeScript๋กœ npm package์— ๋ฐฐํฌํ•˜๊ธฐ | React Custom hook ๋ฐฐํฌ

ruby_s 2022. 12. 30. 20:49
728x90
๋ฐ˜์‘ํ˜•
SMALL

์ด๋ฒˆ์— WebRTC ๊ด€๋ จ hook์„ ๋งŒ๋“ค์—ˆ๋Š”๋ฐ, ๊ณต๋ถ€ํ•˜๋ฉด์„œ ๊ตฌํ˜„ํ•˜๊ธฐ๊นŒ์ง€ ์‹œ๊ฐ„์ด ๊ฝค ๊ฑธ๋ ธ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ๊ทธ๋ž˜์„œ ๋‚ด๊ฐ€ ๋งŒ๋“  ํ›…์„ npm package์— ์˜ฌ๋ ค์„œ ๋‹ค๋ฅธ ๋ถ„๋“ค์ด ๋„์›€์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋ฉด ์ข‹์ง€ ์•Š์„๊นŒ! ๋ผ๋Š” ์ƒ๊ฐ์— ์ฒ˜์Œ์œผ๋กœ! ์˜ฌ๋ ค๋ดค๋‹ค.

https://www.npmjs.com/package/@ruby-s/use-rtc

 

@ruby-s/use-rtc

React hook to connect to WebRTC. Latest version: 1.1.8, last published: 19 hours ago. Start using @ruby-s/use-rtc in your project by running `npm i @ruby-s/use-rtc`. There are no other projects in the npm registry using @ruby-s/use-rtc.

www.npmjs.com

1. npm ๊ฐ€์ž…

npm์— ํŒจํ‚ค์ง€๋ฅผ ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•ด์„œ https://www.npmjs.com/์—์„œ ๊ฐ€์ž…ํ•˜์ž.

2. package.json ํŒŒ์ผ ์ƒ์„ฑ

npm init -y

-y ์˜ต์…ฅ์œผ๋กœ ๋ฐ”๋กœ ๊ธฐ๋ณธ์ ์ธ pakage.json ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

์ด์ œ ๋‚ด ํŒจํ‚ค์ง€์— ๋งž๊ฒŒ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค.

{
  "name": "@ruby-s/use-rtc",
  "version": "1.0.0",
  "description": "React hook to connect to WebRTC",
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "build": "tsc"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/juyeong-s/RTC.git"
  },
  "author": "juyeong-s",
  "license": "MIT",
  "keywords": [
    "React",
    "Hook",
    "WebRTC",
    "useRTC"
  ],
  "bugs": {
    "url": "https://github.com/juyeong-s/RTC/issues"
  },
  "homepage": "https://github.com/juyeong-s/RTC#readme",
  "dependencies": {
    "socket.io-client": "^4.5.4",
    "typescript": "^4.9.3"
  },
  "peerDependencies": {
    "react": ">=16.8.0",
    "react-dom": ">=16.8.0"
  },
  "devDependencies": {
    "@types/node": "^18.11.18",
    "@types/react": "^18.0.26"
  }
}

name

๊ณ ์œ ํ•œ ํŒจํ‚ค์ง€๋ช…์ž…๋‹ˆ๋‹ค.

version

ํŒจํ‚ค์ง€ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค. ์—…๋ฐ์ดํŠธํ•  ๋•Œ๋งˆ๋‹ค ๋ฒ„์ „์„ ๋‹ค๋ฅด๊ฒŒ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ์กด์˜ ๋ฒ„์ „์œผ๋กœ ๋‹ค์‹œ ์˜ฌ๋ฆฌ๋ ค๊ณ  ํ•  ๊ฒฝ์šฐ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋ฏ€๋กœ ์กฐ์‹ฌํ•  ๊ฒƒ.

description

ํŒจํ‚ค์ง€ ์„ค๋ช…์ž…๋‹ˆ๋‹ค.

main

ํ”„๋กœ์ ํŠธ์—์„œ ๊ธฐ๋ณธ ์ง„์ž… ํŒŒ์ผ์„ ์ง€์ •ํ•œ๋‹ค.
TypeScript์˜ ๊ฒฝ์šฐ ts ํŒŒ์ผ์„ ๋นŒ๋“œํ•œ ํ›„ ์ƒ์„ฑ๋œ js ํŒŒ์ผ์ด ์žˆ๋Š” ์œ„์น˜๋กœ ์ง€์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
๋‚˜ ๊ฐ™์€ ๊ฒฝ์šฐ, tsconfig.json ํŒŒ์ผ์— ๋นŒ๋“œ๋œ ํŒŒ์ผ์ด distํด๋” ์•ˆ์— ์ƒ์„ฑ๋˜๋„๋ก ์ง€์ •ํ•ด์ฃผ์—ˆ์œผ๋ฏ€๋กœ main์— dist/index.js๋กœ ์ง€์ •ํ–ˆ๋‹ค.

// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  }
}

 

npm run build -> dist ํด๋” ์•ˆ์— js ํŒŒ์ผ๋“ค ์ƒ์„ฑ๋จ -> ์ฒ˜์Œ ์ง„์ž…ํ•  ํŒŒ์ผ์„ main์— ์ง€์ •

types

์ด ์†์„ฑ์„ TypeScript๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๊ฒฝ์šฐ์— ํ•„์š”ํ•˜๋‹ค. ์œ„์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ build๋ฅผ ํ•˜๋ฉด distํด๋”์— js ํŒŒ์ผ๊ณผ .d.ts ํŒŒ์ผ์ด ํ•จ๊ป˜ ์ƒ์„ฑ๋œ๋‹ค.
์ด๋•Œ .d.ts ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

scripts

์ด ์†์„ฑ์€ TypeScript๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๊ฒฝ์šฐ buildํ•  ํ•„์š”๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์“ฐ์ผ ๊ฒƒ ๊ฐ™๋‹ค. build ๋ช…๋ น์–ด๋กœ tsc ์ปค๋งจ๋“œ๋ฅผ ์ง€์ •ํ•ด์„œ tsํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•˜๋„๋ก ํ•œ๋‹ค.

repository

์ฝ”๋“œ๊ฐ€ ์กด์žฌํ•˜๋Š” ์ฃผ์†Œ๋ฅผ ์ง€์ •ํ•˜๋ฉด ๋œ๋‹ค. npm docs๋กœ ํŒจํ‚ค์ง€ ์ €์žฅ์†Œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด npm ํŒจํ‚ค์ง€ ์˜ค๋ฅธํŽธ์— ๋ณด์ธ๋‹ค.

author

ํŒจํ‚ค์ง€ ์ œ์ž‘์ž์˜ ์ด๋ฆ„์„ ์ง€์ •ํ•œ๋‹ค. ์ด๋ฆ„๋งŒ ํ•ด๋„ ๋˜๊ณ , ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•ด์ฃผ์–ด๋„ ๋œ๋‹ค.

{
  "author": {
    "name": "juyeong-s",
    "email": "happyu9986@gmail.com",
    "url": "http://juyeong-s.com"
  }
}

license

๋ผ์ด์„ผ์Šค๋ฅผ ์ง€์ •ํ•œ๋‹ค.

keywords

ํŒจํ‚ค์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๋Œ€ํ‘œ์ ์ธ ํ‚ค์›Œ๋“œ๋“ค์„ ๋ฐฐ์—ด์˜ ์›์†Œ๋“ค๋กœ ์„ค์ •ํ•ด์ค๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜๋‹จ์— ๋ณด์ž…๋‹ˆ๋‹ค.

bug

ํŒจํ‚ค์ง€์— ๋ฌธ์ œ๋‚˜ ๋ฒ„๊ทธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ๋ณด๊ณ ํ•  ์ˆ˜ ์žˆ๋„๋ก URL์„ ์ง€์ •ํ•œ๋‹ค. ๋ณดํ†ต ๊นƒํ—ˆ๋ธŒ ์ด์Šˆ๋ฅผ ์˜ฌ๋ฆฌ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

homepage

ํ”„๋กœ์ ํŠธ ํ™ˆํŽ˜์ด์ง€๋กœ ์—ฐ๊ฒฐ๋˜๋Š” URL์„ ์ง€์ •ํ•œ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์ด npm ํŒจํ‚ค์ง€์˜ ์˜ค๋ฅธํŽธ์— ๋ณด์ธ๋‹ค.

dependencies

ํŒจํ‚ค์ง€์˜ ๋ฐฐํฌ ์‹œ ํฌํ•จ๋  ์˜์กด์„ฑ ๋ชจ๋“ˆ์„ ์ง€์ •ํ•œ๋‹ค.

peerDependencies

ํŒจํ‚ค์ง€์˜ ํ˜ธํ™˜์„ฑ ๋ชจ๋“ˆ์„ ์ง€์ •ํ•œ๋‹ค.

devDependencies

ํŒจํ‚ค์ง€์˜ ์ง์ ‘ ๋™์ž‘๊ณผ ๊ด€๋ จ์€ ์—†์ง€๋งŒ, ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ ๊ฐœ๋ฐœํ•  ๋•Œ ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ง€์ •ํ•œ๋‹ค. ๋ณดํ†ต ํ…Œ์ŠคํŒ… ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋‚˜ type๊ด€๋ จ ๋ชจ๋“ˆ๋“ค์ด ์—ฌ๊ธฐ ๋“ค์–ด๊ฐ„๋‹ค.
๊ฐœ๋ฐœ์— ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐํฌํ•  ๋•Œ๋Š” ํฌํ•จ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

3. .npmignore ํŒŒ์ผ ์„ค์ •

ํŒจํ‚ค์ง€์— ๋ฐฐํฌํ•˜์ง€ ์•Š์„ ํŒŒ์ผ์ด๋‚˜ ํด๋”๋ฅผ ์ง€์ •ํ•ด์ค€๋‹ค.
๋‚˜๋Š” ts๋กœ ์ž‘์„ฑํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— tsํŒŒ์ผ์ด ์žˆ๋Š” ํด๋”๋Š” ignoreํ•ด์ฃผ๊ณ , js๋งŒ ์˜ฌ๋ฆฌ๋„๋ก ํ–ˆ๋‹ค.

// .npmignore
src/

.gitignore์—๋Š” ๋นŒ๋“œ๋œ js๋Š” ์ œ์™ธํ•˜๊ณ  tsํŒŒ์ผ๋งŒ ์˜ฌ๋ฆฌ๋„๋ก ํ–ˆ๋‹ค.

// .gitignore
node_modules
.env
dist/

 

4. npm์— ์˜ฌ๋ฆฌ๊ธฐ

package.json ํŒŒ์ผ์„ ๋ชจ๋‘ ์„ค์ •ํ•ด์ฃผ์—ˆ๊ณ , ๋ฐฐํฌํ•  hookํŒŒ์ผ๋„ ๋ชจ๋‘ ํฌํ•จ์‹œ์ผฐ๋‹ค๋ฉด ์ด์ œ npm ํŒจํ‚ค์ง€์— ์˜ฌ๋ฆด ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค.

js๋กœ ์ž‘์„ฑํ–ˆ์„ ๊ฒฝ์šฐ npm publish๋กœ ๋ฐ”๋กœ ๋ฐฐํฌํ•˜๋ฉด ๋˜๊ณ ,
ts๋กœ ์ž‘์„ฑํ–ˆ์„ ๊ฒฝ์šฐ npm run build ํ›„ js ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด ์ค€ ํ›„ npm publish๋กœ ๋ฐฐํฌํ•ด์ฃผ๋ฉด ๋œ๋‹ค!

 

728x90
๋ฐ˜์‘ํ˜•
LIST