rollup-endpoint
The easiest way to serve a rollup bundle.
Last updated 3 years ago by mindeavor .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rollup-endpoint 
SYNC missed versions from official npm registry.

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
  }
}));

Current Tags

  • 0.2.2                                ...           latest (3 years ago)

3 Versions

  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (1)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |