<commit_before># bit-bundler-splitter
> bit-bundler plugin for splitting bundles up

This plugin helps slice and dice your application bundle into smaller bundles which we refer to as bundle shards. The more common use case is to split out the vendor (3rd party) modules into a separate bundle. This is to maximize browsers' caching capabilities; generally speaking vendor bundles do not change frequencetly and browsers can cache them rather efficiently. Vendor bundles also tend to be larger than your more frequently changing application bundles, which generally translates to a reduction in traffic.

`bit-bundler-splitter` uses [roolio](https://github.com/MiguelCastillo/roolio) to provide a flexible way to configure matching rules that control how bundles are split. More on this in the examples section.

### Install

```
$ npm install --save-dev bit-bundler-splitter
```

### example

This example shows a basic `bit-bundler` setup with `bit-bundler-splitter` splitting out vendor bundles.

> `bit-bundler-splitter` splits out vendor modules by default when no matching rules are defined.

``` javascript
var Bitbundler = require("bit-bundler");
var jsPlugin = require("bit-loader-js");
var babelPlugin = require("bit-loader-babel");
var splitBundle = require("bit-bundler-splitter");

var bitbundler = new Bitbundler({
  loader: {
    plugins: [
      jsPlugin(),
      babelPlugin()
    ]
  },
  bundler: {
    plugins: [
      splitBundle("dest/splitter-vendor.js", { match: { path: [/\/bower_components\//, /\/node_modules\//] } }),
      splitBundle("dest/splitter-renderer.js", { match: { path: /src\/renderer/ } })
    ]
  }
});

bitbundler
  .bundle({
    src: "src/main.js",
    dest: "dest/splitter-main.js"
  });
```

### API

#### splitBundle( dest: string, options: object )

`bit-bundler-splitter` exports a function that we generally call `splitBundle`.  The first parameter is the destination of where the bundle is going to be written to relative to the current working directory.  The second parameter are options to define matching rules, which is how we configure how bundles are split.

- @param {string} dest - File name where the bundle is going to be written to relative to the working directory
- @param {object} options - Configuration options explained below.

The options that `splitBundle` take are for configuring matching rules to determine which modules go in which bundle. Matching rules can match anything that is in the module object, which includes `path`, `name`, and `source`; matching rules essentially match the shape of modules. These matching rules can be `regex`, `string`, or a `function`.  Please see [roolio matchers](https://github.com/MiguelCastillo/roolio#matchers) for more details on defining rules.


### Examples
Let's take a look at a setup that matches any module name that only has word characters. e.g. "jquery". This is a really simple heuristic for identifying vendor modules, and it is also the default behavior for `bit-bundler-splitter` when no options are provided.

> By default, `bit-bundler-splitter` will split out vendor modules when no options are provided.

``` javascript
splitBundle("dest/vendor.js", {
  match: {
    name: /^\w+/
  }
});
```

This is an example for matching a particular module name:

``` javascript
splitBundle("dest/three.js", {
  match: {
    name: "three"
  }
});
```

You can further specify a regex to match particular paths.

``` javascript
splitBundle("dest/common.js", {
  match: {
    path: /common/
  }
});
```

You can also specify multiple matching rules.

``` javascript
splitBundle("dest/vendor.js", {
  match: {
    name: "jquery",
    path: /views/
  }
});
```


### License

Licensed under MIT<commit_msg>Updated docs to include information about options.dest<commit_after># bit-bundler-splitter
> bit-bundler plugin for splitting bundles up

This plugin helps slice and dice your application bundle into smaller bundles which we refer to as bundle shards. The more common use case is to split out the vendor (3rd party) modules into a separate bundle. This is to maximize browsers' caching capabilities; generally speaking vendor bundles do not change frequently and browsers can cache them rather efficiently. Vendor bundles also tend to be larger than your more frequently changing application bundles, which generally translates to a reduction in traffic.

`bit-bundler-splitter` uses [roolio](https://github.com/MiguelCastillo/roolio) to provide a flexible way to configure matching rules that control how bundles are split. More on this in the examples section.

### Install

```
$ npm install --save-dev bit-bundler-splitter
```

### example

This example shows a basic `bit-bundler` setup with `bit-bundler-splitter` splitting out vendor bundles by matching the path of module. If the module path contains `bower_components` or `node_modules` then it is considered a 3rd party library and it gets push to the vendor bundle. We are also splitting out modules whose path contains `src/renderer` and writing that out as a separate bundle.

> `bit-bundler-splitter` splits out vendor modules by default when no matching rules are defined.

``` javascript
var Bitbundler = require("bit-bundler");
var splitBundle = require("bit-bundler-splitter");

var bitbundler = new Bitbundler({
  loader: [
    "bit-loader-js",
    "bit-loader-babel"
  ],
  bundler: [
    splitBundle("dest/splitter-vendor.js", { match: { path: [/\/bower_components\//, /\/node_modules\//] } }),
    splitBundle("dest/splitter-renderer.js", { match: { path: /src\/renderer/ } })
  ]
});

bitbundler.bundle({
  src: "src/main.js",
  dest: "dest/splitter-main.js"
});
```

### API

#### splitBundle( name: string, options: object )

`bit-bundler-splitter` exports a function that we generally call `splitBundle`.  The first parameter is the name of the bundle. If there is no dest specified in the options, then the name is used as the file path for writing the bundle. The second parameter are options to define matching rules, which is how we configure how bundles are split. Options can also contain `dest` which is where the bundle is written to. `dest` can be a file name or a stream.

- @param {string} name - name of the bundle. When there is no `dest` option specified, then the name is used as the file path to write bundles to.
- @param {object} options - Configuration options explained below.

The primary options that `splitBundle` take are for configuring matching rules to determine which modules go in which bundle. Matching rules can match anything that is in the module object, which includes `path`, `filename`, and `source`; matching rules essentially match the shape of modules. These matching rules can be `regex`, `string`, or a `function`.  Please see [roolio matchers](https://github.com/MiguelCastillo/roolio#matchers) for more details on defining rules.

You can also configure the destination for the bundle, which can be a string (file path) or a writable stream.


### Examples
Let's take a look at a setup that matches any module name that only has word characters. e.g. "jquery". This is a really simple heuristic for identifying vendor modules, and it is also the default behavior for `bit-bundler-splitter` when no options are provided.

> By default, `bit-bundler-splitter` will split out vendor modules when no options are provided.

``` javascript
splitBundle("dest/vendor.js", {
  match: {
    name: /^\w+/
  }
});
```

This is an example for matching a particular module name:

``` javascript
splitBundle("dest/three.js", {
  match: {
    name: "three"
  }
});
```

You can further specify a regex to match particular paths.

``` javascript
splitBundle("dest/common.js", {
  match: {
    path: /common/
  }
});
```

You can also specify multiple matching rules.

``` javascript
splitBundle("dest/vendor.js", {
  match: {
    name: "jquery",
    path: /views/
  }
});
```

Now, let's specify a bundle name and a destination where the bundle is going to be written to.

``` javascript
splitBundle("vendor", {
  dest: "dest/vendor.js",
  match: {
    name: "jquery",
    path: /views/
  }
});
```

Destination can alternatively be a stream.

``` javascript
splitBundle("vendor", {
  dest: process.stdout,
  match: {
    name: "jquery",
    path: /views/
  }
});
```


### License

MIT
{'fraction_non_alphanumeric': 0.10084235860409145, 'fraction_numerical': 0.00036101083032490973, 'mean_word_length': 4.0400242571255305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1576816', 'n_tokens_mistral': 2346, 'n_tokens_neox': 2250, 'n_words': 1020}