-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to specify an alternate tsconfig for production builds #6023
Comments
Sorry, this isn't possible and we have no plans to add support for this. |
@Timer I agree that unused variables is linter's job. But currently TSLint considers this rule deprecated, since it's quite hard for them to maintain it and tsc already has this feature (palantir/tslint#4100). I don't think it's "impossible" to support this ( |
Ultimately, it comes down to being a foot-gun IMO. Users may accidentally configure their If this is necessary, I'd suggest modifying |
Since I only need that unused variable checking, I ended up just running |
Would you @alexkuz mind elaborating a bit more how you did this? |
@alexkuz
and change your build script in package.json:
|
@Timer Why would this not be possible? To me it looks like it would simply involve changing:
in packages/react-scripts/config/paths.js to something "env-based" using the Advanced Configuration "way". |
We need to use This behaviour is breaking our production builds and could be avoided by allowing me to specify a different |
Update: I've worked around this by creating three files: tsconfig.base.json
tsconfig.development.json // inherits from base config
tsconfig.production.json // inherits from base config I added some extra steps to the build to copy the correct config to For example, here is what I added to "scripts": {
// ...
"start": "cp -f ./typescript/tsconfig.development.json ./tsconfig.json && npm install && react-scripts start",
"build": "cp -f ./typescript/tsconfig.production.json ./tsconfig.json && npm install && webpack --config webpack/webpack.config.js --mode development",
// ...
}, |
I can "work around" nearly everything, because JS got' |
Support for multiple tsconfigs is a fundamental requirement for any build tool that claims to support TypeScript. Not having it is the real footgun. The reason is that, in order for intellisense in editors like VSCode to work, your root However, when building your app, you obviously don't want to include everything. In fact, it is very dangerous to do so. If one of your app's components accidentally imported something from Storybook or node, you wouldn't get an error and build/type-check time. Therefore, you need to create a separate This is how other tools like Angular CLI work, and it is how it is supposed to work. It's the whole reason TypeScript supports multiple tsconfig files and extending from each other. |
FWIW adding |
Having "
This work-around doesn't work for the use case of excluding files from the production build. |
Agree. |
Hi, I believe a feature to use different tsconfigs is crucial, why aren't you planning to add it? |
Hello from Cypress! 👋🏻 Support for multiple Cypress 10 supports Component Testing and recommends adding /// <reference types="cypress" /> Depending on the version of VSCode, you need to reload (Cmd + R) for the new reference types to take effect. This is a poor DX. Lastly, files executed in the node context, like In projects that have: mixed toolchains, mixed environments (node vs browser), mixed module systems (esm, cjs), it's critical to support diversity in compilation options. |
You can achieve this with react-app-rewired: // config-overrides.js
const path = require('path');
module.exports = {
paths: function(paths) {
return {
...paths,
appTsConfig: path.join(__dirname, 'tsconfig.production.json'),
};
},
}; |
Guys! There is a PR for it. It would make me so happy to see such a crucial change merged CarlRibbegaardh but it seems to have gotten stale. |
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
Steps to Reproduce
tsconfig.prod.json
with different settings thantsconfig.json
:yarn build
or whatever you have configured to do a production build withreact-scripts
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.
The text was updated successfully, but these errors were encountered: