JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q82774F
  • License MIT

Expertly rolled JavaScript. API + CLI for for bundling opinionated JavaScript with Rollup.js

Package Exports

  • handroll

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (handroll) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

handroll NPM version Build Status Coverage Status Dependency Status Gitter chat

Expertly rolled JavaScript

JavaScript API and CLI for for bundling opinionated JavaScript with Rollup. Tastes great with shortcake.

Install

$ npm install handroll --save-dev

CLI

$ handroll src/index.coffee --format web > index.js

JavaScript API

Handroll's JavaScript API provides a similar interface to Rollup, with the bundle step being optional (and only useful if you want to cache the intermediate bundle). In most cases you'll want to juse use .write or .generate directly.

Built-in support for many file-types (CoffeeScript, Stylus, Pug, JSON, etc). Rollup.js options, plugins and write destination are automatically derived for you from format option in most instances. Defaults can of course be easily over-written.

import handroll from 'handroll'

bundle = await handroll.bundle
  entry: 'src/index.coffee'  # Path to entry module

  # The following defaults may configured to customize logging and override the
  # behavior of handroll.

  # compilers:  null    Customize compilers used per-filetype
  # es3:        false   Emit slightly more ES3-compliant output
  # executable: false   Include shebang and chmod+x output
  # external:   false   Set package.json dependencies as external
  # sourceMap:  true    Collect and save source maps

  # quiet:      false   Suppress default output
  # details:    false   Print extra details about bundle

  # minify:     false   Use uglify to minify bundle
  # strip:      false   Remove debugging and console log statements

# Write ES module for use by bundlers (with external deps)
await bundle.write format: 'es'

# Write CommonJS module for use by Node.js (with external deps)
await bundle.write format: 'cjs'

# Write IIFE bundle with all deps for web
await bundle.write format: 'web'

# Write executable with shebang using new entry module
await handroll.write
  entry:  'src/cli.coffee'
  format: 'cli'

Motivating example

rollup        = require 'rollup'

autoTransform = require 'rollup-plugin-auto-transform'
builtins      = require 'rollup-plugin-node-builtins'
coffee        = require 'rollup-plugin-coffee-script'
commonjs      = require 'rollup-plugin-commonjs'
es3           = require 'rollup-plugin-es3'
filesize      = require 'rollup-plugin-filesize'
globals       = require 'rollup-plugin-node-globals'
json          = require 'rollup-plugin-json'
nodeResolve   = require 'rollup-plugin-node-resolve'
pug           = require 'rollup-plugin-pug'
strip         = require 'rollup-plugin-strip'
stylup        = require 'rollup-plugin-stylup'

postcss      = require 'poststylus'
autoprefixer = require 'autoprefixer'
comments     = require 'postcss-discard-comments'
lost         = require 'lost-stylus'

pkg = require './package.json'

plugins = [
  autoTransform()
  globals()
  builtins()
  coffee()
  pug
    pretty:                 true
    compileDebug:           true
    sourceMap:              false
    inlineRuntimeFunctions: false
    staticPattern:          /\S/
  stylup
    sourceMap: false
    plugins: [
      lost()
      postcss [
        autoprefixer browsers: '> 1%'
        'lost'
        'css-mqpacker'
        comments removeAll: true
      ]
    ]
  json()
  nodeResolve
    browser: true
    extensions: ['.js', '.coffee', '.pug', '.styl']
    module: true
    jsnext: true
  commonjs
    extensions: ['.js', '.coffee']
    sourceMap: false
  es3()
  strip()
  filesize()
]

bundle = await rollup.rollup
  entry:   'src/app.coffee'
  plugins: plugins

# App bundle for browser
await bundle.write
  dest:   'public/js/app.js'
  format: 'iife'

License

MIT