Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment specific tsconfig.json

Is there a way how to set tsconfig.json environmentally specific such as tsconfig.prod.json and tsconfig.dev.json?

I want to have sourceMap and comments on dev environment, but I want to remove these on production.

like image 817
Andree Avatar asked Oct 25 '17 08:10

Andree


1 Answers

You can use extends for this.

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

Example: tsconfig.prod.json

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

If you use webpack and ts-loader you can then set it like this:

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'
                    },
                },

            ],
         },
like image 132
Ogglas Avatar answered Sep 23 '22 17:09

Ogglas