概要
- 新規プロジェクトを始める際に簡単に導入ができるようにコピペ用のスターターを作成する
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