question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a way to specify an alternate tsconfig for production builds

See original GitHub issue

Is this a bug report?

No. This is a feature request. Our team is now using CRA with TS and it is great! One thing we can’t seem to find is any information on is having different TS compiler settings when doing a production build. Simply adding a tsconfig.prod.json appears to have no effect. I can’t seem to find a documented way to add this and it would be super useful!

Did you try recovering your dependencies?

N/A

Which terms did you search for in User Guide?

TypeScript https://reactjs.org/docs/static-type-checking.html#typescript

Environment

Environment Info:

  System:
    OS: macOS 10.14.1
    CPU: x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
  Binaries:
    Node: 10.14.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/Projects/cirrus-admin-webapp/node_modules/.bin/npm
  Browsers:
    Chrome: 70.0.3538.110
    Firefox: 63.0.3
    Safari: 12.0.1
  npmPackages:
    @types/react: 16.7.7 => 16.7.7
    @types/react-dom: 16.0.11 => 16.0.11
    react: 16.6.3 => 16.6.3
    react-dom: 16.6.3 => 16.6.3
    react-scripts: 2.1.1 => 2.1.1
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

  1. Add TS to your project as outlined in the docs.
  2. Attempt to add a tsconfig.prod.json with different settings than tsconfig.json:
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "noUnusedLocals": true
  }
}
  1. Run yarn build or whatever you have configured to do a production build with react-scripts
  2. Notice the settings aren’t applied.

Expected Behavior

It would honor the tsconfig.prod.json

Actual Behavior

It honors the original tsconfig.json.

Reproducible Demo

N/A. I can add one later if people have any issues reproducing.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:52
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

66reactions
Timercommented, Dec 11, 2018

Sorry, this isn’t possible and we have no plans to add support for this. It would be better to accomplish this via linting, e.g. TSLint.

44reactions
Obiwarncommented, Feb 22, 2019

@alexkuz Add a tsconfig.production.json:

{
    "extends": "./tsconfig.json",  
    "compilerOptions": {
      "noUnusedLocals": true,
      "skipLibCheck": true
    },
  "exclude": ["**/*.test.ts", "*.test.tsx"]
}

and change your build script in package.json:

...
  "scripts": {
    "start": "react-scripts start",
    "build": "tsc -p tsconfig.production.json && react-scripts build",
    "deploy": "npm run build && firebase deploy",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure react-script so that it doesn't override tsconfig ...
I'm currently using create-react-app to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to ......
Read more >
Setting up Path Alias in TypeScript and tsc build without error
Third, go to tsconfig.json and add the paths alias options inside compilerOptions. ... Therefore, you need tscpaths for production build.
Read more >
Documentation - Integrating with Build Tools - TypeScript
How to use TypeScript with other build tools.
Read more >
Configuring TypeScript compiler - inDepthDev
This article explores in depth essential TypeScript configuration options. We'll learn how to configure input and output files location, file types, transpiling ...
Read more >
How To Use Typescript with Create React App | DigitalOcean
The tsconfig.json file is used to configure TypeScript projects, similar to how package.json is for JavaScript projects. The tsconfig.json ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found