Git Product home page Git Product logo

bundleify's Introduction

bundleify Build Status Greenkeeper badge

Bundle your JS with browserify with preconfigured transforms

Install

$ npm install --save bundleify

Usage

var bundleify = require('bundleify')

bundleify({
  entry: 'app.js',
  destination: 'build' 
}, function (err) {
  //=> wrote build to `./build`  
})

bundleify applies the following settings and transforms:

  • es2020, a transpiler for a tiny subset of ES6
  • source maps
  • exposes your entry as require('app')
  • flattens configuration and uses it to replace environment variables
  • applies minification transforms when in compression mode:

Transforms

Browserify transforms applied to the bundle are not global by default, but uglifyify and es2020 are explicitly run globally. That means the following features are limited to your code and do not run on your dependencies:

  • Environment variable replacement

API

bundleify(options, callback) -> undefined

options

Required
Type: object

entry

Required
Type: string

The relative path to the entry file.

destination

Required
Type: string

The relative path to the destination folder.

basedir

Type: string
Default: process.cwd()

The base directory from which the entry and destination paths are resolved.

compress

Type: boolean
Default: false

Toggles minification/compression transforms (see Usage).

config

Type: object
Default: {}

Nested configuration to be transformed into environment variables that will be replaced in the bundle. Given the following config:

{
  foo: {
    bar: 'baz'
  }
}

You can write the following code:

console.log(process.env.FOO_BAR)
//=> baz

Any environment variables that are not explicit defined in the configuration will be set to undefined.

filename

Type: string
Default: bundle.js

The destination filename.

callback

Required
Type: function
Arguments: err

A callback that will be called with a build error if applicable, otherwise null.

License

MIT © Ben Drucker

bundleify's People

Contributors

bendrucker avatar greenkeeper[bot] avatar ajoslin avatar

Stargazers

Andrew Chou avatar Jake Burden avatar Tim Wisniewski avatar Charlike Mike Reagent avatar Takashi Fujita avatar Jack Hanford avatar Manuel Vila avatar nichoth avatar Marwan Hilmi avatar Yosh avatar Chris Vickery avatar  avatar Daniel Lewis avatar Mikey avatar

Watchers

 avatar James Cloos avatar Yosh avatar  avatar

bundleify's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

include unassertify

I'm quite a fan of using require('assert') in my packages. I reckon I might not be the only one. Perhaps it would be an option to include unassertify as a way to extract assert calls from final bundles, shaving away 20kb of require('util') and require('assert') calls. I've been using it for quite a while, and it has never slowed down my builds by any noticeable amount. What do you reckon? Thanks!

Pass in a browserify instance

Instead of accepting options, allow passing in a browserify instance.

Right now, I can't run global transforms or plugins on the final bundle, since they can't be defined from package.json.

Something like this seems like it would work:

function build (options, callback) {
  var bundle = browserify({debug: true})
    .transform(myTransform, {global: true})
    .plugin(myPlugin)

  return bundleify(bundle, options, done)
}

Thoughts?

expose optimizations as browserify transform, plugin

I reckon it'd be cool if the transforms in bundleify could be exposed as a single transform. Perhaps this needs to be a separate package tho, but I quite like the idea of doing:

$ browserify -g bundleify/transform -p bundleify/plugin | bundleify/compress

Or something along those lines. Makes it easier to point people to a single repo as "the solution to browserify optimizations"; with app-specific transforms as another thing (like brfs and yo-yoify).

The downside of this being that bundleify ships with browserify included, which kind of goes against this, but I feel having common ground for optimizating builds would be grand. Thoughts?

Enable ES2020 (tiny ES6 subset)

These are the features of ES6 I use anyway in stuff I only expect to run in Node or Chrome, e.g. test suites.

The version of es2020 would be ~1.0.1, so no new syntax would be supported without a minor release of bundleify. No syntax would be disabled for transpilation without a major version bump.

Thoughts @ajoslin @chrisinajar @ahdinosaur? Are these defaults helpful or do you guys configure syntax support on a per-project basis?

CLI

Is it a good thing to add a CLI to this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.