1
0

Node.js でタイプスクリプトを導入する早見表

Last updated at Posted at 2024-03-09

概要

  • 新規プロジェクトを始める際に簡単に導入ができるようにコピペ用のスターターを作成する

1. フォルダ作成とnpmの初期化

# フォルダの作成
mkdir myproject
# 作成したフォルダに移動
cd myproject
# npm の初期化
npm init -y

2. TypeScriptのインストール

# コンパイラの導入と型定義の追加
npm install --save-dev typescript @types/node

3. TypeScriptの設定ファイルの作成

tsconfig.json
{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": true,
    "strict": true
  },
  "include": [
    "./src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    ".history"
  ]
}

4. コンパイルスクリプトの追記

package.json
"scripts": {
  "build": "tsc",
  "start": "node dist/index.js"
}

5. コンパイルと実行

npm run build
npm start
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0