Bundle Typescript 3.2.4 for the browser in a single file
Asked Answered
H

0

6

Originally these where JS files and all was well. But I wanted some simple type checking, so I converted to TypeScript.

What I would like is to compile all the .ts files into one .js suitable for use in the browser with a simple script tag.

This project does NOT include webpack, so please refrain from webpack related instructions.

I tried this

tsc main.ts --module amd --outFile main.js

and

tsc main.ts --module system --outFile main.js

But both seem to require I include a further third party library on the page.

Is there a way I can get all the files concatenated together so everything just works? I tried running the output of the amd built version through the browserify command, but no dice.

If this doesn't work I will just go back to .js and include with script tags like normal.


TLDR: How can I get bundled ts into a single js with no requirejs or systemjs dependency on the page?

Hyaena answered 11/4, 2019 at 0:19 Comment(5)
--module none should do it, but it means no modules, really - you can use only dependencies that are accessible via globals.Chiefly
@Chiefly that defeats the whole thing. I want to share type info.Hyaena
Then you have to use module bundler. Browserify will probably work. But it's the bundler that takes modules compiled to javascript and produces a script that could be loaded with <script> tag. With modules, you can't use TypeScript compiler to produce single .js file directly.Chiefly
@Chiefly ok how can I use browserify for this. I tried and did not have success so far.Hyaena
sorry I don't know about browserify, I use webpack for this.Chiefly

© 2022 - 2024 — McMap. All rights reserved.