2020-05-06 18:21:13 -04:00
|
|
|
## Bundling
|
|
|
|
|
|
|
|
`deno bundle [URL]` will output a single JavaScript file, which includes all
|
|
|
|
dependencies of the specified input. For example:
|
|
|
|
|
|
|
|
```
|
2020-07-31 05:12:20 -04:00
|
|
|
> deno bundle https://deno.land/std@$STD_VERSION/examples/colors.ts colors.bundle.js
|
2020-09-27 22:46:19 -04:00
|
|
|
Bundle https://deno.land/std@$STD_VERSION/examples/colors.ts
|
|
|
|
Download https://deno.land/std@$STD_VERSION/examples/colors.ts
|
|
|
|
Download https://deno.land/std@$STD_VERSION/fmt/colors.ts
|
|
|
|
Emit "colors.bundle.js" (9.83KB)
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
If you omit the out file, the bundle will be sent to `stdout`.
|
|
|
|
|
|
|
|
The bundle can just be run as any other module in Deno would:
|
|
|
|
|
|
|
|
```
|
2020-05-07 07:48:48 -04:00
|
|
|
deno run colors.bundle.js
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
The output is a self contained ES Module, where any exports from the main module
|
|
|
|
supplied on the command line will be available. For example, if the main module
|
|
|
|
looked something like this:
|
|
|
|
|
|
|
|
```ts
|
|
|
|
export { foo } from "./foo.js";
|
|
|
|
|
|
|
|
export const bar = "bar";
|
|
|
|
```
|
|
|
|
|
|
|
|
It could be imported like this:
|
|
|
|
|
|
|
|
```ts
|
2020-09-27 06:22:32 -04:00
|
|
|
import { bar, foo } from "./lib.bundle.js";
|
2020-05-06 18:21:13 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
Bundles can also be loaded in the web browser. The bundle is a self-contained ES
|
|
|
|
module, and so the attribute of `type` must be set to `"module"`. For example:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<script type="module" src="website.bundle.js"></script>
|
|
|
|
```
|
|
|
|
|
|
|
|
Or you could import it into another ES module to consume:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<script type="module">
|
|
|
|
import * as website from "website.bundle.js";
|
|
|
|
</script>
|
|
|
|
```
|