-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: typescript project reference incremental build support #1250
Comments
Do you mean this? https://esbuild.github.io/api/#incremental |
Incremental build on one module level is a different thing. |
@electroma Do you mean using TypeScript Project References + referencing a non-yet-built file in the main/module/exports in one of the There are two workarounds for this:
@ Evan - the use case is something like this:
So: esbuild cannot simply follow the references and build the other project, since it wouldn't fit into how esbuild works. Something that is theoretically possible would be to read the referenced It does seem rather complicated though. esbuild would have to check every file to see whether it is a part of a referenced project within the context of the current tsconfig. The redirected source files would take precedence over built files, since those could be out of date. I personally explored writing a plugin to resolve such cases, but using one of the workarounds seems like a better solution. |
@nihalgonsalves thank you for sharing your experience! We tried both workarounds too:
For now the workaround we rely on is to use Regarding support of project refs in ESBuild - I see your point, and I think that ESBuild probably can't and shouldn't play catch with mainstream TSC. |
Is this something that other bundlers support? Such as Webpack, Parcel, Rollup, or Browserify? If other bundlers don't do this, then I don't see why esbuild should need to do this. |
@evanw, it's already a relatively long thread, and in the original feature request I stated "Both rollup and webpack plugins have support for this feature". I have several modules using rollup and webpack and they both support incremental cross-module build out-of-the-box. |
I tried but I was unable to get the test case in #1250 (comment) to work in either Webpack or Rollup (or Parcel): https://github.com/evanw/esbuild-issue-1250. What am I missing? |
@nihalgonsalves do you also have |
This is not a bundler problem. FWIW The |
If
One benefit from this approach that I like is that it avoids the duplication of helper functions that might otherwise find themselves injected in each intermediate build. |
@evanw turns out me writing that entire config in a comment wasn't perfect. I modified the example a bit with workspace/tsconfig fixes: And as @ggoodman pointed out, what I mentioned in my initial comment was using paths as a workaround, and this works automatically since esbuild supports paths: Looking up the source file for a given Also: Rollup still doesn't work with this config, the official plugin seems to support neither project references, nor paths by default. (When testing, make sure to delete the
@electroma That's not true, if you combine it with project references it should still work for type-checking. And for esbuild this does not matter - it still gets through ~100k LoC in < 2 seconds. @jaredpalmer You could also just run |
@nihalgonsalves |
This seems like a good thing to experiment with in a plugin to me. |
I'm going to close this then. It sounds like this needs to be solved in a layer on top of esbuild instead. |
I have built a plugin for that: https://github.com/smacker/esbuild-plugin-ts-references |
@smacker that's a good effort, unfortunately it can't be used with webpack's https://github.com/privatenumber/esbuild-loader |
I was able to get this working using a custom "exports": {
".": {
"myOrganizationName:bundler": "./src/index.ts",
"default": "./out/index.js"
}
} Then esbuild --conditions=myOrganizationName:bundler ... |
Btw note that this issue doesn't just force you to make sure your local dependency packages are compiled. Pointing ➜ esbuild ./src/extension.ts --conditions=myOrganizationName:bundler --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify
dist/extension.js 636.0kb
⚡ Done in 82ms
➜ esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify
dist/extension.js 785.7kb
⚡ Done in 77ms |
Normally [SWC does not support project references](swc-project/swc#2156), but by specifying the source files in `exports`, using with a special condition name, we can trick webpack into resolving the source files, instead of the JS files from `lib`, and therefore letting SWC transpile the sources. With this we can move away from `ts-loader`, and still avoid compilation with `tsc` as prebuilt step. Inspired by evanw/esbuild#1250 (comment).
Normally [SWC does not support project references](swc-project/swc#2156), but by specifying the source files in `exports`, using with a special condition name, we can trick webpack into resolving the source files, instead of the JS files from `lib`, and therefore letting SWC transpile the sources. With this, we can move away from `ts-loader`, and still avoid compilation with `tsc` as a prebuilt step. Inspired by evanw/esbuild#1250 (comment).
Normally [SWC does not support project references](swc-project/swc#2156), but by specifying the source files in `exports`, using with a special condition name, we can trick webpack into resolving the source files, instead of the JS files from `lib`, and therefore letting SWC transpile the sources. With this, we can move away from `ts-loader`, and still avoid compilation with `tsc` as a prebuilt step. Inspired by evanw/esbuild#1250 (comment).
Normally [SWC does not support project references](swc-project/swc#2156), but by specifying the source files in `exports`, using with a special condition name, we can trick webpack into resolving the source files, instead of the JS files from `lib`, and therefore letting SWC transpile the sources. With this, we can move away from `ts-loader`, and still avoid compilation with `tsc` as a prebuilt step. Inspired by evanw/esbuild#1250 (comment).
I have a TypeScript monorepo setup with multiple node modules and TypeScript project references between them.
TSC does support
tsc -b
which will perform an incremental build on the module and all referenced projects.Both rollup and webpack plugins have support for this feature.
Though I can't see anything like that in ESBuild.
Am I missing something?
The text was updated successfully, but these errors were encountered: