diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2019-11-21 03:02:08 +1100 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-11-20 11:02:08 -0500 |
commit | 8d977d0117c2b61e6714cec9e4238f4ba0a56195 (patch) | |
tree | 5992f83fa50067f59aec1f1c9008d6c3fe6e921d /std/manual.md | |
parent | 1912ed674097588adb7b83e7b78043b2168821f3 (diff) |
feat: Support named exports on bundles. (#3352)
Diffstat (limited to 'std/manual.md')
-rw-r--r-- | std/manual.md | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/std/manual.md b/std/manual.md index d2f5f348c..434d2d17b 100644 --- a/std/manual.md +++ b/std/manual.md @@ -797,27 +797,50 @@ Particularly useful ones: dependencies of the specified input. For example: ``` -> deno bundle https://deno.land/std/examples/colors.ts +> deno bundle https://deno.land/std/examples/colors.ts colors.bundle.js Bundling "colors.bundle.js" Emitting bundle to "colors.bundle.js" 9.2 kB emitted. ``` +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: ``` deno colors.bundle.js ``` -Bundles can also be loaded in the web browser. For example: +The output is a self contained ES Module, which 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 +import { foo, bar } from "./lib.bundle.js"; +``` + +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 src="website.bundle.js"></script> +<script type="module" src="website.bundle.js"></script> ``` -Bundles, whether loaded in the web browser, or in Deno, would run the root -module which is specified on the command line when creating the bundle, so put -any initiation logic in that module. +Or you could import it into another ES module to consume: + +```html +<script type="module"> + import * as website from "website.bundle.js"; +</script> +``` ### Installing executable scripts |