環境固有のtsconfig.json 質問する

環境固有のtsconfig.json 質問する

tsconfig.jsonなどの環境固有の設定方法はありますか?tsconfig.prod.jsontsconfig.dev.json

sourceMap開発環境ではと を保持したいのですcommentsが、本番環境ではこれらを削除したいと思います。

ベストアンサー1

これに使えますextends

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#configuration-inheritance-with-extends

例:tsconfig.prod.json

{
  "extends": "./tsconfig",
  "compilerOptions": {
    "sourceMap": "false"
  }
}

を使用する場合はwebpackts-loader次のように設定できます。

https://github.com/TypeStrong/ts-loader#configfile-string-defaulttsconfigjson

module: {
    rules: [
        // All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
        {
            test: /\.tsx?$/,
            use: [
                {
                    loader: 'babel-loader',
                    options: {
                        babelrc: false,
                        plugins: ['react-hot-loader/babel'],
                    },
                },
                {
                    loader: 'ts-loader',// (or awesome-typescript-loader)
                    options: {
                        configFile: 'tsconfig.prod.json'
                    },
                },

            ],
         },

おすすめ記事