Lonnie Best
Lonnie Best

Reputation: 11399

Converting a typescript library into a standalone javascript file

How can I convert a typescript library into a single javascript file?

For example, oak is a 3rd party library that provides itself via typescript. In deno, you can import oak like this:

import { Application } from "https://deno.land/x/oak/mod.ts";

I would like to convert https://deno.land/x/oak/mod.ts to a standalone javascript file, that could be imported like this:

import { Application } from "./oak.js";

How can I accomplish this conversion?

Upvotes: 1

Views: 663

Answers (1)

Evandro Pomatti
Evandro Pomatti

Reputation: 15124

You can use the bundler tool with the deno bundle command:

deno bundle https://deno.land/x/oak/mod.ts oak.js

You can now import oak.js and use it on your JavaScript code:

import { Application } from "./oak.js";

const app = new Application();

app.use((ctx) => {
  ctx.response.body = "Hello World!";
});

await app.listen({ port: 8000 });

Upvotes: 1

Related Questions