Awesome
<p align="center"> <h1 align="center">deno-rollup</h1> </p> <p align="center"> Next-generation ES module bundler for <a href="https://deno.land/">Deno</a> ported from <a href="https://github.com/rollup/rollup">Rollup</a>.</p> <p align="center"> <a href="https://github.com/cmorten/deno-rollup/tags/"><img src="https://img.shields.io/github/tag/cmorten/deno-rollup" alt="Current version" /></a> <img src="https://github.com/cmorten/deno-rollup/workflows/Test/badge.svg" alt="Current test status" /> <a href="https://doc.deno.land/https/deno.land/x/drollup/mod.ts"><img src="https://doc.deno.land/badge.svg" alt="Deno docs" /></a> <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs are welcome" /></a> <a href="https://github.com/cmorten/deno-rollup/issues/"><img src="https://img.shields.io/github/issues/cmorten/deno-rollup" alt="deno-rollup issues" /></a> <img src="https://img.shields.io/github/stars/cmorten/deno-rollup" alt="deno-rollup stars" /> <img src="https://img.shields.io/github/forks/cmorten/deno-rollup" alt="deno-rollup forks" /> <img src="https://img.shields.io/github/license/cmorten/deno-rollup" alt="deno-rollup license" /> <a href="https://github.com/cmorten/deno-rollup/graphs/commit-activity"><img src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" alt="deno-rollup is maintained" /></a> </p> <p align="center"> <a href="https://deno.land/x/drollup"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fdrollup%2Fmod.ts" alt="deno-rollup latest /x/ version" /></a> <a href="https://github.com/denoland/deno/blob/main/Releases.md"><img src="https://img.shields.io/badge/deno-^1.11.4-brightgreen?logo=deno" alt="Minimum supported Deno version" /></a> <a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/drollup/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fdep-count%2Fx%2Fdrollup%2Fmod.ts" alt="deno-rollup dependency count" /></a> <a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/drollup/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fupdates%2Fx%2Fdrollup%2Fmod.ts" alt="deno-rollup dependency outdatedness" /></a> <a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/drollup/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fcache-size%2Fx%2Fdrollup%2Fmod.ts" alt="deno-rollup cached size" /></a> </p>Deprecation Notice: Deno now supports a --compat
flag that allows for the running of Node modules in Deno through the Node compatibility layer. See the official Rollup docs on Deno usage.
From Deno 1.25 there is also has support for using NPM specifiers:
import { rollup } from "npm:rollup";
deno run --unstable --allow-env --allow-read --allow-write npm:rollup
This renders the core and CLI parts of this module obsolete.
Future efforts will be spent bolstering the Node compatibility layer instead of keeping this module aligned with Rollup for Node.
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 in Deno - supporting core Deno features out-of-the-box such as URL imports, Typescript and JSX.
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.58.0+0.20.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.58.0+0.20.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);
await bundle.close();
Or using the watch
API:
import { watch } from "https://deno.land/x/drollup@2.58.0+0.20.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 contains 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 contains 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.
Known deviations from Rollup:
- Deno code support: TypeScript and URL imports supported out-of-the-box.
- CLI does not currently support some nested "dot" flags, namely:
--no-treeshake.*
,--watch.*
and--no-watch.*
. - CLI does not currently support the
--plugin
flag. - Some warnings have yet to be implemented.
Where further deviations / incompatibility are found, please raise an issue.
Plugins
A suite of deno-rollup compatible plugins are available in the plugins directory.
Examples
To run the examples you have a couple of options:
Direct from repository
-
Run the deno-rollup
helloDeno
example directly from the repository:deno run --allow-read="./" --allow-write="./dist" --allow-net="deno.land" --allow-env --unstable https://deno.land/x/drollup@2.58.0+0.20.0/examples/helloDeno/rollup.build.ts
This will create a
./dist
directory with the bundled files in your current working directory.
Clone
-
Clone the deno-rollup repo locally:
git clone git://github.com/cmorten/deno-rollup.git --depth 1 cd deno-rollup
-
Then enter the desired examples directory and run the build script:
cd examples/helloDeno deno run --allow-read="./" --allow-write="./dist" --allow-net="deno.land" --allow-env --unstable ./rollup.build.ts
This will create a
./dist
directory with the bundled files in the current directory. -
Further details are available in each example directory.
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.
Derived works other than from Rollup are attributed with their license in source.