The JS runtimes
Published in

The JS runtimes

Distribute application with Deno

Introduction

Bundle

Command

deno bundle <root-module.ts> <output-file.ts>

Examples

//app.tsfunction f(i: number) {
return i+100;
}
console.log(f(1));
> deno bundle app.ts Check file:///private/var/tmp/a.ts
Bundle file:///private/var/tmp/a.ts
function f(i) {
return i + 100;
}
console.log(f(1));
//app.ts
import * as a from "./a.ts"
import {delay} from "https://deno.land/std/async/mod.ts"
await delay(a.f(500));//a.ts
export function f(i: number) {
return i+100;
}
> deno bundle app.ts app.js//app.jsfunction f(i) {
return i + 100;
}
function delay(ms) {
return new Promise((res)=>setTimeout(()=>{
res();
}, ms)
);
}
await delay(f(500));
//app.ts
import * as u from "https://deno.land/std/uuid/mod.ts"
export function get() {
return u.v4.generate()+'-'+u.v4.generate();
}
export function getV1() {
return u.v1.generate()+'-'+u.v1.generate();
}
deno bundle app.ts app.js
Check file:///private/var/tmp/app.ts
Bundle file:///private/var/tmp/app.ts
//
.... code omitted as it's too long ....
//wc -l app.js
//495

Compile

deno compile <permissions> <root-module.ts> <output>

Examples

//app.tsfunction f(i: number) {
return i+100;
}
console.log(f(1));
> deno compile app.ts
Check file:///private/var/tmp/app.ts
Bundle file:///private/var/tmp/app.ts
Compile file:///private/var/tmp/app.ts
Emit app
> du -kh app
77M app
> ./app
101
//app.ts
import * as a from "./a.ts"
import {delay} from "https://deno.land/std/async/mod.ts"
await delay(a.f(500));
//a.ts
export function f(i: number) {
return i+100;
}
> deno compile app.ts 
Check file:///private/var/tmp/app.ts
Bundle file:///private/var/tmp/app.ts
Compile file:///private/var/tmp/app.ts
Emit app
> du -kh app
77M app
> deno compile --target x86_64-unknown-linux-gnu app.ts 
Check file:///private/var/tmp/app.ts
Bundle file:///private/var/tmp/app.ts
Compile file:///private/var/tmp/app.ts
Checking https://dl.deno.land/release/v1.10.2/deno-x86_64-unknown-linux-gnu.zip
Download has been found
Archive: /var/folders/k0/3447gbp16vl309gg50ygclwr0000gn/T/.tmpL0I5id/deno.zip
inflating: deno
Emit app
> du -kh app
77M app
> deno compile --target x86_64-pc-windows-msvc app.ts 
Check file:///private/var/tmp/app.ts
Bundle file:///private/var/tmp/app.ts
Compile file:///private/var/tmp/app.ts
Checking https://dl.deno.land/release/v1.10.2/deno-x86_64-pc-windows-msvc.zip
Download has been found
Archive: /var/folders/k0/3447gbp16vl309gg50ygclwr0000gn/T/.tmpOHamID/deno.zip
inflating: deno.exe
Emit app

> du -kh app.exe
54M app.exe

Size comparison

//======== Deno code ========
export function f(i: number) {
return i+100;
}
console.log(f(1));//======== C++ code ========
#include <iostream>
int f(int a) {
return a+100;
}
int main() {
printf("%d", f(1));
}
//======== Go code ========
package main
import "fmt"func f(num int) int {
return num+100;
}
func main() {
fmt.Printf("%d", f(1));
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store