Repository
Current version released
3 years ago
Dependencies
Bundler
About
Bundler is a zero configuration bundler with the web in mind.
- smart splits dependencies
- handles
top level await
- typescript and javascript
- handles static
import
andexport
statements - handles dynamic
import()
statements - handles
fetch()
statements - handles
WebWorker
imports - handles
ServiceWorker
imports
- handles static
- html
- handles
<link>
,<script>
,<style>
and<img>
tags - handles
style
attributes - handles
webmanifest
files
- handles
- css
- handles
css
@import
statements - supports postcss-preset-env stage 2 and nesting-rules by default
- handles
- CLI
- built in code optimization and minification with
--optimize
option - built in file watcher with
--watch
option
- built in code optimization and minification with
Installation
Bundler CLI
deno install --unstable --allow-read --allow-write --allow-net --allow-env --name bundler https://deno.land/x/bundler/cli.ts
Info: You might need to specify --root /usr/local
.
Usage
Bundler CLI
bundler bundle index.html=index.html
Option | Description | Default |
---|---|---|
-c, âconfig <FILE> | Load tsconfig.json configuration file | {} |
âout-dir <DIR> | Name of out_dir | âdistâ |
-h, âhelp | Prints help information | |
âimport-map <FILE> | UNSTABLE: Load import map file | {} |
âoptimize | Optimize source code | false |
-L, âlog-level | Set log level [possible values: debug, info] | debug |
-q, âquiet | Suppress diagnostic output | false |
-r, âreload | Reload source code âreloadâReload everything âreload=index.tsâReload only standard modules âreload=a.ts,b.tsâReloads specific modules |
false |
âwatch | Watch files and re-bundle on change | false |
Dev Server CLI
deno run --unstable --allow-read --allow-write --allow-net --allow-env https://deno.land/x/bundler/server_cli.ts
SPA Dev Server CLI
deno run --unstable --allow-read --allow-write --allow-net --allow-env https://deno.land/x/bundler/spa_server_cli.ts
API
Bundler Example
import { createBundler } from "https//deno.land/x/bundler/mod.ts";
const bundler = createBundler(); // create bundler instance with default plugins
const input = "src/index.html";
const outputMap = { [input]: "index.html" };
const { bundles } = await bundler.bundle([inputs], { outputMap });
Advanced Bundler Example
import { Bundler } from "https//deno.land/x/bundler/mod.ts";
const input = "src/index.html";
const outputMap = { [input]: "index.html" };
const plugins = [ ⌠];
const bundler = new Bundler(plugins); // create bundler instance with custom plugins
const graph = await bundler.createGraph([input], { outputMap });
const chunks = await bundler.createChunks(inputs, graph);
const bundles = await bundler.createBundles(chunks, graph);
Bundler Server
import { BundlerServer } from "https//deno.land/x/bundler/mod.ts";
const server = new BundlerServer();
await server.listen({ port: 8000 });
Smart Splitting
Bundler automatically analyzes the dependency graph and splits dependencies into separate files, if the code is used in different entry points. This prevents code duplication and allows multiple bundle files to share code.
Examples
Bundler CLI
Bundler API
Unstable
This module requires deno to run with the --unstable
flag. It is likely to
change in the future.