# @transclusion/bundle

Simple and efficient file bundling for Node.js.

```sh
yarn add @transclusion/bundle --dev
```

[![build status](https://img.shields.io/travis/transclusion/bundle/master.svg?style=flat-square)](https://travis-ci.org/transclusion/bundle)
[![npm version](https://img.shields.io/npm/v/@transclusion/bundle.svg?style=flat-square)](https://www.npmjs.com/package/@transclusion/bundle)

## Usage

### CLI
```sh
usage: bundle <command> <options>

  Commands:
  – build
  – watch
```

When using the CLI, add a `.bundlerc` to the project root:

```json
{
  "name": "main",
  "dest": "./dist",
  "source": "src/client",
  "target": "[name][ext]",
  "plugins": [
    ["babel", {"presets": ["flow", "env"]}],
    "commonjs",
    "iife",
    "uglifyjs"
  ]
}
```

### API

`bundle` can also be used as a Node.js module.

#### Example
```js
import bundle from '@transclusion/bundle'
import bundlePluginCommonjs from '@transclusion/bundle-plugin-commonjs'
import bundlePluginIife from '@transclusion/bundle-plugin-iife'
import path from 'path'

bundle.build({
  name: 'main',
  basedir: __dirname,
  dest: path.resolve(__dirname, 'static'),
  source: './main.js',
  output: '[name][ext]',
  plugins: [
    bundlePluginCommonjs,
    bundlePluginIife
  ]
}).then(() => {
  console.log('bundled main.js')
}).catch(err => {
  console.error(err.stack)
  process.exit(1)
})
```
