-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Write typescript as modules, but output js without modules #39446
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
typescript has |
TypeScript also supports incremental compilation of composite projects. For example, the compiler itself is broken into composite projects, but does not use modules. Maybe that would help? |
We want to have js built for each ts, next to the ts, and that ts used modules while js does not.
Well, not sure... Each project needs to have its own config file and we need to link all the projects? Then when one project was built whole dependent project is built, even though some are not changed? Then we need to think about projects and which groups to create as projects... It seems that it complicates our usage significantly. Our use case is fairly simple - when one ts file is changed we want to build only that file and dependent ones, creating our own dependencies through projects instead of modules adds unneeded complexity... To be a bit more precise - this is what we do:
I guess we're not the only ones with this problem... tsc incremental watch works well for modules (and it is clear why, it has dependency data), ts code is clear with modules (you know where from are the references used), and all that is good related to ts. But there's no reason to imply that someone who write modules in ts wants them in js as well, since the aforementioned goodies are ts-only and not needed in the transpiled js. |
This is likely not happening because this actually isn't all that common of a situation, and the solution here is already implemented in things like rollup, whose configuration docs show just how complicated this process is. It's not something we'd want to re-implement unless it was absolutely critical for a large number of people. |
This is my use-case, I have an OpenApi specification that is used to generate Typescript client code from. I would like to build this Typescript code into a single javascript file that is not a module and that can be imported into a Polymer 2 project using a simple script tag. Edit: This Polymer 2 project may be upgraded to Polymer 3 or rewritten using some other framework, but that's not happening right now. |
I would also accept this as an alternative to my existing issue: #33206 The TSC compiler is just so close to being a great standalone compiler for outputting compact javascript for the web. There's just this frustrating requirement that you either use webpack/rollup or triple-slash-references. EDIT: I closed my existing issue #33206 and I think rollup does what I want, but I still think it's a shame that rollup's functionality is only provided by the typescript compiler when using triple-slash references, and must be supplemented by the rollup package when using standard import syntax. |
Currently working on an Electron app and I’ve always used TypeScript’s namespace functionality together with --outFile, and it’s always worked great. It would be amazing if I could keep this workflow but also import modules from Node.js standard library with |
Just trying to keep this alive in 2023. The use case is there. In my case, I'm working in a more niche JS runtime (ServiceNow/Rhino) which doesn't use explicit exports, and so adding this in would definitely serve my use case. |
Search Terms
Searched the whole internet for anything like it, only webpack and browserify related 'solutions' are proposed.
Suggestion
Split module options in tsconfig so typescript modules could be set separately from output target modules.
Use Cases
Our usecase:
versioning, caching, etc.
So currently we have two bad options - don't use modules (unacceptably slow build time) or use modules (get the output that we don't want). Currently we 'mitigate' the issue by removing parts of js tsc has output (removing stuff we recognize as related to exports and require), but that's just terrible.
Even worse, even if we were to use modules, require / exports are inlined even in output we want to inline to index.html as critical JS...
Examples
I guess I explained it all above.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: