設定用の設定.JSON
4625 ワード
なぜ我々はそれが必要ですか?
技術的には、私たちのマシンは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 .
この記事があなたに役立つことを願っています.私は、この記事についてあなたのフィードバックを受けるより幸せです.この貴重な時間を読んでくれてありがとう.
Reference
この問題について(設定用の設定.JSON), 我々は、より多くの情報をここで見つけました https://dev.to/maithanhdanh/configuration-for-tsconfig-json-3bg5テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol