Using webpack to generate typescript libraries with typing files
<p>Currently my process for building is:</p>

<ul>
<li>Write lots of typescript files with ES6 module syntax</li>
<li>Generate an index.ts which re-exports all modules from one point</li>
<li>Compile to CommonJS + System</li>
<li>Output Descriptor/Typing files</li>
</ul>

<p>This results in an index.js file which re-exports all the internal files without the developer consuming it needing to know about it, as well as a lot of d.ts files which mirror the file structure.</p>

<p>Now this works, but if I were to take this approach to the browser I would need to webpack up all the js or it would be a http request nightmare pulling in all the individual files. Currently this library would be consumed as a dependency for other libraries, so it is not an end point for logic or anything it is a module/library.</p>

<p>Now the main question is with webpack I know I can load TS in and get a commonJS module out, however I cannot find any way to generate <code>d.ts</code> files with webpack. So is there a way for me to use webpack as the compiler/packager in this scenario and have an output <code>my-lib.js</code> and <code>my-lib.d.ts</code> rather than the current approach which yields lots of individual files.</p>

<p>== Extra Clarification on Use Case ==</p>

<p>Just to try and make sure everyone is on the same page here when I say it is a library that would be re-used what I mean is that this is something that would be loaded via npm or jspm or something as a module dependency for other modules.</p>

<p>So for example let us pretend jquery doesn't exist and I am going to create it but write it in typescript for other developers to consume in both JS and TS. Now typescript outputs both js files and d.ts files, the js files are to be used as you would expect, but the d.ts files explain to other typescript files what the types contained within the library are.</p>

<p>So assuming I have developed jquery in TS as listed above, I would then want to publish this output (be it created by webpack or tsc) on npm/jspm/bower etc. So then others can re-use this library in their own projects.</p>

<p>So webpack typically is used to package an "application" if you will, which contains logic and business concerns and is consumed directly as an entry point to a larger set of concerns. In this example it would be used as a compilation and packaging step for a library and would be consumed via <code>var myLib = require("my-lib");</code> or similar.</p>