#
ts-node ์ ๋๊ฒฝ๋กts-node ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น
yarn add -D typescript @types/node nodemon ts-node tsconfig-paths
package.json์์ nodemon์ผ๋ก ์คํ
"scripts": { "dev": "nodemon -r ts-node src/index.ts" // nodemon src/index.ts๋ก๋ ์คํ๋จ}
tsconfig.json์ baseUrl๊ณผ path ์ค์
"baseUrl": ".","paths": { "src/*": ["src/*"]}
โ ์ด์ ์ปดํ์ผ์ ๋์ง๋ง, ์ปดํ์ผ๋ ํ์ผ์ node, ts-node๊ฐ ์ธ์ํ์ง ๋ชปํ๋ค.
โ tsconfig-paths ๋ชจ๋๋ก ๊ฐ๋ฅ
"scripts": { "dev": "nodemon --exec ts-node -r tsconfig-paths/register src/index.ts"}
๋น๋ ํ์๋ ๋์ํ๊ฒ ํ๋ ค๋ฉด
ts-node ๋ชจ๋์ ํตํด ์๋์ํค๋ ๋ฐฉ๋ฒ์ด ์๋ค.
"scripts": { "start": "ts-node -r tsconfig-paths/register dist/index.js" // ๋๋ // "start": "node -r ts-node/register/transpile-only -r tsconfig-paths/register dist/index.js"}
tsconfig-paths์ bootstrap์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ.
// tsconfig-paths-bootstrap.jsconst tsConfigPathFile = require('./tsconfig.paths.json');const tsConfig = require('./tsconfig.json');const tsConfigPaths = require('tsconfig-paths'); tsConfigPaths.register({ baseUrl: tsConfig.compilerOptions.outDir, paths: tsConfigPathFile.compilerOptions.paths,});
// package.json"scripts" { "start": "node -r ./tsconfig-paths-bootstrap.js dist/src/index.js"}