設定用の設定.JSON



なぜ我々はそれが必要ですか?
技術的には、私たちのマシンはtypescript(ts)を理解することができません.ですから、JavaScriptを別の形式に変換する必要があります.
設定ファイルに感謝tsconfig.json , プロセスの出力を制御することができます.

構成

マイ設定
以下の設定は、私のTSプロジェクトの大部分に使用する例です.
{
  "extends": "@tsconfig/recommended/tsconfig.json",
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "allowJs": true,
    "importHelpers": true,
    "jsx": "react",
    "alwaysStrict": true,
    "sourceMap": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitAny": false,
    "noImplicitThis": false,
    "strictNullChecks": false,
    "outDir": "./build",
    "baseUrl": ".",
    "paths": {
      "@server/*": ["src/*"],
      "@tests/*": ["__tests__/*"],
      "@config/*": ["src/config/*"],
      "@domain/*": ["src/domain/*"],
      "@controller/*": ["src/controller/*"],
      "@middleware/*": ["src/middleware/*"]
    }
  },
  "include": ["src/**/*", "__tests__/**/*"],
  "exclude": ["node_modules", "build"]
}

使う
我々は、ちょうどそれをコピーしますtsconfig.json rootレベルでインストールを忘れないでください@tsconfig/recommended 走ることで
# for npm
npm install --save-dev @tsconfig/recommended

#for yarn
yarn add --dev @tsconfig/recommended
注:上記の構成では、部分paths 私が最も推薦するオプションです.組み合わせmodule-alias , モジュールをもっと読みやすくすることができますtsconfig-paths サーバの起動時に設定されたパスを読み込む

あなたが使用する代わりに、イメージで見ることができるように../../config/logger , 私は単に@config/logger .

その他のオプション
意味やその他のオプションはtsconfig.json documentation . それとも、playaround ここでは、基本的にTS Config タブ、結果は右パネルに表示されます.

このポストは私のシリーズの最初のステップです'あなた自身のTypesScript Express Template 'を作成します.あなたがそれをする機会があれば、それがどれくらい痛いかを知っているでしょう
コーヒーを買ってください☕ buymeacoffee .
この記事があなたに役立つことを願っています.私は、この記事についてあなたのフィードバックを受けるより幸せです.この貴重な時間を読んでくれてありがとう.