Skip to content
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

Support --declarationOutFile for bundling declarations for commonjs and es6 modules #8372

Closed
raybooysen opened this issue Apr 29, 2016 · 16 comments
Labels
Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@raybooysen
Copy link

raybooysen commented Apr 29, 2016

This is very similar to #8305.

In our world we are using webpack to bundle our typescript library which has many levels of nesting. For example:

mylib\
  services\
    index.ts
    service1.ts
  foo\
     bar\
       index.ts
       barImpl.ts

At the moment our current approach is to export everything into one top-level index.ts which means consumers lose the nesting and we have to write the .d.ts files ourselves

Ideally we'd like consumers to import modules like this (and avoid a single index.ts file at the top level that exports everything in a non-nested structure):

import { service1 } from 'myLib/services

However it is not obvious from the documentation how to write a .d.ts file that supports this layout when this is how the webpack bundle is structured. As a second part, how can I have TS auto-generate the .d.ts files for us so that we can have a single definition file for our bundled JS

@basarat
Copy link
Contributor

basarat commented May 4, 2016

As a second part, how can I have TS auto-generate the .d.ts files for us so that we can have a single definition file for our bundled JS

Suggestion: Separate what webpack does with what tsc does:

  • TSC : compiles .ts files to .js + .d.ts files.
  • Webpack: Bundles these .js files in a bundle.js

This way your published module should contain : bundle.js, all the .js, all the .d.ts And people get to chose if they use bundle.js (not webpack user) or all the .js + all the .d.ts (webpack user)

I might be wrong 🌹

@mhegazy
Copy link
Contributor

mhegazy commented May 4, 2016

Does my sample in #8305 (comment) address the issue? if no, why not?

@mhegazy mhegazy added Question An issue which isn't directly actionable in code Docs The issue relates to how you learn TypeScript labels May 4, 2016
@raybooysen
Copy link
Author

@mhegazy not exactly.

Your sample shows how to consume npm-libraries. As a library developer, using webpack to bundle, what is the best process to expose modules that "match" the folder listing and at the same time generate a single .d.ts file that includes the definitions for these bundled javascript modules.

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2016

i see. that is not a supported feature now. i would assume you want to have a --declarationFile that will bundle all your module declarations, but not your js output (currently --outFile bundles both .js and .d.ts output). is this accurate?

@raybooysen
Copy link
Author

Yes, I think that is accurate. I think this is a common workflow, where TS developers will bundle a production bundle but still want to provide a d.ts file for other typescript consumers.

Happy to take advice on other alternatives.

@mhegazy mhegazy added Suggestion An idea for TypeScript Help Wanted You can do this and removed Docs The issue relates to how you learn TypeScript Question An issue which isn't directly actionable in code labels May 11, 2016
@mhegazy mhegazy added this to the Community milestone May 11, 2016
@mhegazy mhegazy changed the title Recommendation for exposing nested Typescript modules in a Bundled JS files Support --declarationOutFile for bundling declarations for commonjs and es6 modules May 11, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2016

thanks, updating the title to reflect the request.

PRs are welcomed.

@desjoerd
Copy link

desjoerd commented Nov 4, 2016

Any updates on this?

@cesarvarela
Copy link

I'm just realizing that Typescript isn't very node.js developer friendly.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 27, 2017

I'm just realizing that Typescript isn't very node.js developer friendly.

curious to know why is that.

@simonsarris
Copy link

simonsarris commented Apr 5, 2017

@mhegazy I came to this issue thinking something similar, but that TypeScript is not very JS library developer friendly. It is not easy or obvious how to create a single .js file to use as a library on the web from several .ts classes, while this is trivial to do with plain JavaScript and requires no tools. TypeScript seems to require a lot of external tools to make projects like that work. In this case at least webpack is necessary to produce such single-file output, which really surprised me going in to TypeScript. (Or if not webpack, writing a script to strip the import/export from each file and concat all your .ts files before tsc runs)

The issue here for developers of web libraries is the other side of that coin. If I want to create a single .js file to use on the web as a library, I have to do something totally different to make a single .d.ts file. Specifying outFile won't work if your module is "commonjs", so something like declarationOutFile might be nice.

@maikelvanhaaren
Copy link

Any update on this?

@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2017

Any update on this?

The issue is marked as Accepting PRs. so PRs are welcomed.

@dwasyluk
Copy link

Monthly checking for any updates on this :)

@mtford90
Copy link

Pwetty pwetty pweaseee

@darren-dev
Copy link

New year update?

@raybooysen
Copy link
Author

Closing as a dupe of #4433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

10 participants