-
Notifications
You must be signed in to change notification settings - Fork 12.8k
tsconfig.json should support multiple configurations #37884
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
Comments
related #21951 |
I had a similar problem about a year ago so I built a tool to help manage all the tsconfig.json files in a monorepo. https://github.com/isomorphic-typescript/ts-monorepo |
What do you guys think about supporting a |
I'm having a similar problem, not having this feature forces me to have duplicate configs in my monorepo. |
The team took a stance on that here, but I haven't looked to see if anything's changed about their stance since then. |
I don't see how we're supposed to use TypeScript in cross-platform code in conjunction with For example: import { someFunc } from 'zlib-platform'; In Node this resolves to |
Search Terms
multiple configurations, transitive closure
Suggestion
When using multiple packages in a monorepo, it is common to have a
tsconfig.shared.json
that all packages extend in their individualtsconfig.json
. The current system makes it difficult to support various build configurations across packages (such as "dev" vs. "prod").Because a property named
"config"
seems redundant in a file namedtsconfig.json
, I'll borrow the term select from Bazel and propose the following new option in atsconfig.json
file for defining configurations:To complement this,
tsc
would have to support a new--select
flag:Ideally, it would also be possible to parameterize paths such as
outDir
so that you could also define this on the basecompilerOptions
intsconfig.shared.json
:though I haven't been able to get
"outDir"
to do what I want intsconfig.shared.json
in my own project, so there might be more work to do on that front.Use Cases
I want to be able to have a shared
tsconfig.json
that defines multiple configurations in one place that can be shared across multiple modules, as opposed to the current situation where we need O(M ⋅ C)tsconfig.json
files where M is the number of modules and C is the number of configurations. A detailed example is below.Examples
I have a Yarn workspace where each package is under the
modules/
folder, so my rootpackage.json
contains the following:I also have a
shared.tsconfig.json
in the root of my Yarn workspace where I define the"compilerOptions"
that I want all packages in the workspace to use. (For example, I set"target": "es2019"
inshared.tsconfig.json
.) Each folder undermodules/
contains its owntsconfig.json
file that contains the line:and there is also a
"references"
property with the appropriate list of relative paths to other packages in the workspace.Ideally, each such
tsconfig.json
would contain only"extends"
and"references"
, but it seems I have to redeclare"compilerOptions.outDir"
and"include"
in each of these files even though the values are the same in each one (["src/**/*"]
and"./dist"
, respectively).OK, so far, so good, but now I want to be able to build my entire Yarn workspace with a different set of
compilerOptions
, specifically:Ideally, I would be able to specify this in one place and leverage the
"references"
I already had to define so I could compile one.ts
file or package and all of its transitive deps with these compiler options. (I happen to be usingts-loader
in Webpack, so my ultimate output is a single.js
file, which perhaps biases my expectations here.)Unfortunately, there does not appear to be any clean way to do that. I could go through and define a
tsconfig.es3.json
in each of my packages that looks like this:though even if I did that, I'm not sure I could build all of my modules as ES3 with a one-liner as I did in my original
package.json
file. Now I'm faced with the additional incidental complexity of:tsconfig.es3.json
files and ensuring all of them are in sync.tsc -b -p tsconfig.es3.json
or something like that.With the
--select
proposal, I could avoid the extratsconfig.json
files and still build via a one-liner:I would expect if any of the
tsconfig.json
files undermodules/*
did not define a"universal"
configuration, the build command would fail (or at least the strictness should be configurable).Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: