- 2.58.0+0.20.0Latest
- 2.52.7+0.19.1
- 2.52.7+0.19.0
- 2.50.5+0.18.2
- 2.50.5+0.18.1
- 2.50.5+0.18.0
- 2.42.3+0.17.1
- 2.42.3+0.17.0
- 2.41.0+0.16.1
- 2.41.0+0.16.0
- 2.39.1+0.15.0
- 2.39.0+0.14.0
- 2.38.5+0.13.0
- 2.38.5+0.12.0
- 2.38.5+0.11.0
- 2.38.4+0.10.0
- 2.38.4+0.9.1
- 2.38.4+0.9.0
- 2.38.4+0.8.0
- 2.38.1+0.7.4
- 2.38.0+0.7.3
- 2.38.0+0.7.2
- 2.38.0+0.7.1
- 2.38.0+0.7.0
- 2.38.0+0.6.1
- 2.38.0+0.6.0
- 2.37.1+0.5.1
- 2.37.1+0.5.0
- 2.36.2+0.4.1
- 2.36.2+0.4.0
- 2.36.2+0.3.0
- 2.36.1+0.2.0
- 2.36.1+0.1.0
deno-rollup
Next-generation ES module bundler for Deno ported from Rollup.
Table of Contents
Overview
Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application.
This library extends Rollup so that it can be used within Deno scripts to bundle Deno code.
Installation
deno-rollup can be used either through a command line interface (CLI) with an optional configuration file, or else through its JavaScript API.
CLI
To install the CLI run:
deno install -f -q --allow-read --allow-write --allow-net --allow-env --unstable https://deno.land/x/drollup@2.37.1+0.5.0/rollup.ts
And follow any suggestions to update your PATH
environment variable.
You can then use the CLI to bundle your modules:
# compile to an ESM
rollup main.js --format es --name "myBundle" --file bundle.js
You can also rebuild the bundle when it’s source or config files change on disk using the --watch
flag:
# recompile based on `rollup.config.ts` when source files change
rollup -c --watch
JavaScript API
You can import deno-rollup straight into your project to bundle your modules:
import { rollup } from "https://deno.land/x/drollup@2.37.1+0.5.0/mod.ts";
const options = {
input: "./mod.ts",
output: {
dir: "./dist",
format: "es" as const,
sourcemap: true,
},
};
const bundle = await rollup(options);
await bundle.write(options.output);
Or using the watch
API:
import { watch } from "https://deno.land/x/drollup@2.37.1+0.5.0/mod.ts";
const options = {
input: "./src/mod.ts",
output: {
dir: "./dist",
format: "es" as const,
sourcemap: true,
},
watch: {
include: ["src/**"],
},
};
const watcher = await watch(options);
watcher.on("event", (event) => {
// event.code can be one of:
// START — the watcher is (re)starting
// BUNDLE_START — building an individual bundle
// * event.input will be the input options object if present
// * event.outputFiles cantains an array of the "file" or
// "dir" option values of the generated outputs
// BUNDLE_END — finished building a bundle
// * event.input will be the input options object if present
// * event.outputFiles cantains an array of the "file" or
// "dir" option values of the generated outputs
// * event.duration is the build duration in milliseconds
// * event.result contains the bundle object that can be
// used to generate additional outputs by calling
// bundle.generate or bundle.write. This is especially
// important when the watch.skipWrite option is used.
// You should call "event.result.close()" once you are done
// generating outputs, or if you do not generate outputs.
// This will allow plugins to clean up resources via the
// "closeBundle" hook.
// END — finished building all bundles
// ERROR — encountered an error while bundling
// * event.error contains the error that was thrown
});
// This will make sure that bundles are properly closed after each run
watcher.on("event", (event) => {
if (event.code === "BUNDLE_END") {
event.result.close();
}
});
// stop watching
watcher.close();
Documentation
Please refer to the official Rollup Documentation.
Example
To run the example:
Clone the deno-rollup repo locally:
git clone git://github.com/cmorten/deno-rollup.git --depth 1 cd deno-rollup
Then enter the example directory and run the build script:
cd example deno run --allow-read="./" --allow-write="./dist" --allow-net="deno.land" --unstable ./rollup.build.ts
Further details are available in the example README.
Contributing
License
deno-rollup is licensed under the MIT License.
The license for the Rollup library, which this library adapts, is available at ROLLUP_LICENSE.