<commit_before># browserify-shim [![build status](https://secure.travis-ci.org/thlorenz/browserify-shim.png)](http://travis-ci.org/thlorenz/browserify-shim)

Shims modules that aren't installed as `npm` modules so they can be browserified even if they aren't commonJS
compatible.

```js
var browserify = require('browserify')
  , shim = require('browserify-shim');

var bundled = browserify({ debug: true })

    // jquery attaches itself to the window as '$' so we assign the exports accordingly
  .use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', exports: '$' }))

    // underscore is commonJS compliant, so no further export is needed which we specify by assigning exports 'null'
  .use(shim({ alias: 'underscore', path: './js/vendor/underscore.js', exports: null }))

  .addEntry('./js/entry.js')
  .bundle();

fs.writeFileSync(builtFile, bundled);
```

## Installation

    npm install browserify-shim

## Features

- shims **non commonJS** modules in order for them to be **browserified** by specifying an alias, the path to the file and
  the identifier under which the module attaches itself to the global `window` object
- handles even those modules out there that just declare a `var foo = ...` on the script level and assume it gets attached to the
  `window` object since the only way they will ever be run is in the global context - "ahem, ... NO?!"
- loads commonJS modules that are not residing in your `node_modules` from a specific path
- includes `depends` to support shimming libraries that depend on other libraries to be in the global namespace
- makes `define` and **if an export is specified** also `module` be `undefined` in order to prevent improper authored
  libs from attaching their export to the `window` because they think they are being required via `commonJS`. This can cause problems,
  e.g., when libraries are improperly concatenated like
  [here](https://github.com/mhemesath/r2d3/blob/918bd076e4f980722438b2594d1eba53a522ce75/r2d3.v2.js#L222). For more info
  read comment inside [this
  fixture](https://github.com/thlorenz/browserify-shim/blob/master/test/fixtures/shims/lib-with-exports-define-global-problem.js)

## Dependents

Some libraries depend on other libraries to have attached their exports to the window for historical reasons :(.
(hopefully soon we can truly say that this bad design is history)

As an example [backbone.stickit](http://nytimes.github.com/backbone.stickit/) depends on Backbone, underscore.js,
and jQuery or Zepto.

We would properly declare its dependents when shimming it as follows:

**Please note** that we are **defining exports** for `underscore` and `backbone` **although both are commonJS compatible**.
We need to do this in order to make sure that they get attached to the `window` as well as being exported since
`backbone.stickit` expects them to be globally defined.

For more info see Features: "making define and module be undefined"

```js
var bundled = browserify()
  .use(shim({ alias: 'jquery'     ,  path: './js/vendor/jquery.js'     ,  exports: '$' }))
  .use(shim({ alias: 'underscore' ,  path: './js/vendor/underscore.js' ,  exports: '_' }))
  .use(shim({ alias: 'backbone'   ,  path: './js/vendor/backbone.js'   ,  exports: 'Backbone' }))
  .use(shim({
      alias: 'backbone.stickit'
    , path: './js/vendor/backbone.stickit.js'
    , exports: null
    , depends: { jquery: '$', underscore: '_', backbone: 'Backbone' }  
    })
  )
  .addEntry('./js/entry.js')
  .bundle();
```

**Note:** the order of shim declarations doesn't matter, i.e. we could have shimmed `backbone.stickit` at the very top
(before the libraries it depends on).

If a shim depends on only one other shim you can pass just that (instead of an `Array`), e.g.: 

```js
var underscore =  { alias: 'underscore', path: './js/vendor/underscore.js', exports: null }

[..]
  .use(shim({ alias: 'backbone', path: './js/vendor/backbone.js', exports: null, depends: underscore })
[..]
```

## Examples

- [shim-jquery](https://github.com/thlorenz/browserify-shim/tree/master/examples/shim-jquery)
- [shim-underscore](https://github.com/thlorenz/browserify-shim/tree/master/examples/shim-underscore)
<commit_msg>more important stuff marked<commit_after># browserify-shim [![build status](https://secure.travis-ci.org/thlorenz/browserify-shim.png)](http://travis-ci.org/thlorenz/browserify-shim)

Shims modules that aren't installed as `npm` modules so they can be browserified even if they aren't commonJS
compatible.

```js
var browserify = require('browserify')
  , shim = require('browserify-shim');

var bundled = browserify({ debug: true })

    // jquery attaches itself to the window as '$' so we assign the exports accordingly
  .use(shim({ alias: 'jquery', path: './js/vendor/jquery.js', exports: '$' }))

    // underscore is commonJS compliant, so no further export is needed which we specify by assigning exports 'null'
  .use(shim({ alias: 'underscore', path: './js/vendor/underscore.js', exports: null }))

  .addEntry('./js/entry.js')
  .bundle();

fs.writeFileSync(builtFile, bundled);
```

## Installation

    npm install browserify-shim

## Features

- shims **non commonJS** modules in order for them to be **browserified** by specifying an alias, the path to the file and
  the identifier under which the module attaches itself to the global `window` object
- handles even those modules out there that just declare a `var foo = ...` on the script level and assume it gets attached to the
  `window` object since the only way they will ever be run is in the global context - "ahem, ... NO?!"
- loads commonJS modules that are not residing in your `node_modules` from a specific path
- includes `depends` to support shimming libraries that depend on other libraries to be in the global namespace
- makes `define` and **if an export is specified** also `module` be `undefined` in order to prevent improper authored
  libs from attaching their export to the `window` because they think they are being required via `commonJS`. This can cause problems,
  e.g., when libraries are improperly concatenated like
  [here](https://github.com/mhemesath/r2d3/blob/918bd076e4f980722438b2594d1eba53a522ce75/r2d3.v2.js#L222). For more info
  read comment inside [this
  fixture](https://github.com/thlorenz/browserify-shim/blob/master/test/fixtures/shims/lib-with-exports-define-global-problem.js)

## Dependents

Some libraries depend on other libraries to have attached their exports to the window for historical reasons :(.
(hopefully soon we can truly say that this bad design is history)

As an example [backbone.stickit](http://nytimes.github.com/backbone.stickit/) depends on Backbone, underscore.js,
and jQuery or Zepto.

We would properly declare its dependents when shimming it as follows:

**Please note** that we are **defining exports** for `underscore` and `backbone` **although both are commonJS compatible**.
We need to do this in order to make sure that they get attached to the `window` as well as being exported since
`backbone.stickit` **expects them to be globally defined**.

For more info see Features: "making define and module be undefined"

```js
var bundled = browserify()
  .use(shim({ alias: 'jquery'     ,  path: './js/vendor/jquery.js'     ,  exports: '$' }))
  .use(shim({ alias: 'underscore' ,  path: './js/vendor/underscore.js' ,  exports: '_' }))
  .use(shim({ alias: 'backbone'   ,  path: './js/vendor/backbone.js'   ,  exports: 'Backbone' }))
  .use(shim({
      alias: 'backbone.stickit'
    , path: './js/vendor/backbone.stickit.js'
    , exports: null
    , depends: { jquery: '$', underscore: '_', backbone: 'Backbone' }  
    })
  )
  .addEntry('./js/entry.js')
  .bundle();
```

**Note:** the order of shim declarations doesn't matter, i.e. we could have shimmed `backbone.stickit` at the very top
(before the libraries it depends on).

If a shim depends on only one other shim you can pass just that (instead of an `Array`), e.g.: 

```js
var underscore =  { alias: 'underscore', path: './js/vendor/underscore.js', exports: null }

[..]
  .use(shim({ alias: 'backbone', path: './js/vendor/backbone.js', exports: null, depends: underscore })
[..]
```

## Examples

- [shim-jquery](https://github.com/thlorenz/browserify-shim/tree/master/examples/shim-jquery)
- [shim-underscore](https://github.com/thlorenz/browserify-shim/tree/master/examples/shim-underscore)

{'fraction_non_alphanumeric': 0.12750716332378223, 'fraction_numerical': 0.008595988538681949, 'mean_word_length': 4.126682986536108, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, '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': '30792', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2543, 'n_words': 919}