How to build a single ES6 module from several TypeScript files (for a frontend library)
<p>The code of my frontend library is split into several source files.</p>

<p>Example:</p>

<pre><code>// a.ts
function a() {}

// b.ts
function b() {}

// main.ts
const myLib = {
    a: a,
    b: b
}
</code></pre>

<p>I need to build one ES6 module (ie. one JavaScript file) that exports only <code>myLib</code>, as the default export.</p>

<p>I see two options. The first one:</p>

<ol>
<li>Run <code>tsc</code> to compile each file to JavaScript;</li>
<li>Concatenate all the generated JS files into a single file <code>my-lib.js</code>;</li>
<li>Append the code needed by ES6 (<code>export …</code>).</li>
</ol>

<p>The second one:</p>

<ol>
<li>Concatenate all the TypeScript files into a single file <code>my-lib.ts</code>;</li>
<li>Append the export: <code>export default myLib</code>;</li>
<li>Run <code>tsc</code> on the concatenated file.</li>
</ol>

<p>Both options are ugly and loose the <code>map</code> file.</p>

<p>Is there a better way to do that?</p>