npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-endpoint

v0.2.2

Published

The easiest way to serve a rollup bundle.

Downloads

197

Readme

rollup-endpoint

Easily serve a JavaScript bundle – bundled with rollup.js – from an express.js endpoint. No grunt/gulp, no build files, no required configuration – just pure data.

Installation

$ npm install rollup-endpoint --save

Usage - Easy Version

Assuming you have the following directory structure:

client/
└── main.js

server.js
package.json

Then you can write the following as your server.js:

// server.js
var rollup = require('rollup-endpoint');
var app  = require('express')();

app.get('/assets/app-bundle.js', rollup.serve({
  entry: __dirname + '/client/main.js'
}));

console.log("Listening on port 5555...");
app.listen(5555);

Then run node server.js.

Now any GET request to localhost:5555/assets/app-bundle.js will compile and rollup the JS file located at ./client/main.js. Any import statements within main.js will be included in the final output, too.

Advanced Usage

rollup-endpoint passes all your options along to rollup itself, so you can specify any option as described in the rollup JavaScript API.

When the NODE_ENV environment variable is set to production, rollup-endpoint will automatically cache and gzip your bundle output.

Plugins

Plugins are configured in the same way as rollup's JavaScript API.

Here's a useful example. In production, you might want to transpile your code to ES5, as well as minify it. However, you probably don't want waste CPU cycles doing the same in development. Here's how you can do that:

var rollupOptions = { entry: 'my-file.js' };

if ( process.env.NODE_ENV === 'production' ) {
  rollupOptions.plugins = [
    require('rollup-plugin-buble')(),
    require('rollup-plugin-uglify')(),
  ]
}

app.get('/app-bundle.js', rollup.serve(rollupOptions))

Generate Options

If you need to configure the rollup generate options, you can pass them as generateOptions:

app.get('/assets/app-bundle.js', rollup.serve({
  entry: __dirname + '/client/main.js',
  generateOptions: {
    format: 'amd',
    sourceMap: true, // defaults to `false` in production
  }
}));