Mark Tyers
Mark Tyers

Reputation: 3247

Using Deno to Compile TypeScript to JavaScript

I'm working on some Deno projects and would like to be able to compile TypeScript to JavaScript to run in the browser (since TS is not yet supported). When I worked with NodeJS I installed the tsc compiler using npm but it seems overkill to install a second JavaScript runtime (NodeJS) just to get access to tsc. Does Deno have a compiler built-in?

I'm running Ubuntu server.

Upvotes: 7

Views: 6885

Answers (3)

Jeff Hykin
Jeff Hykin

Reputation: 2627

Sadly, As of Deno 1.31, the built-in bundler is now deprecated.

However, the built-in bundler was never really made to do web bundling, its just designed to bundle all the code into one file.

If that is all you want (one big JS file) I've created a deno package that tries to stay true to the original deno bundle:
https://github.com/jeff-hykin/deno_bundle. It uses the official deno plugin for ES build under the hood. It supports node builtin imports but will never support npm imports.

If you specifically want to bundle for the web, I'd recommended Vite (deno install -g npm:vite) with the deno plugin or some other dedicated bundling tool

Upvotes: 8

Enger
Enger

Reputation: 23

You can now use deno compile to compile your source code –with TypeScript support out of the box– to standalone executables.

This allows distribution of a Deno application to systems that do not have Deno installed. Under the hood, it bundles a slimmed down version of the Deno runtime along with your JavaScript or TypeScript code.

Cross-compiling to different target architectures is supported using the --target flag.

Upvotes: 1

Mr. Hedgehog
Mr. Hedgehog

Reputation: 2885

There is built in bundler, so you don't need separate tool.

Upvotes: 4

Related Questions