browserify / browserify/browserify

Do not expose Buffer / process via insertModuleVars if builtins are disabled

Open
#1,108 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.7k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I was wondering, if we could change `browserify` to not provide `Buffer` and `process` variables via `insert-module-globals` if `builtins: false` is specified in the `browserify` configuration.

There exists a number of libraries on npm that gracefully handle the fact that these variables might not be available, i.e. [sax-js](https://github.com/isaacs/sax-js).

To properly support these libraries and clean browser bundles we must specify something like this at the moment which is error prone and verbose:

``` javascript
var b = browserify({
builtins: false,
insertGlobalVars: {
process: function () {
return 'undefined';
},
Buffer: function () {
return 'undefined';
}
}
});
```

`insertGlobalVars` will crash otherwise because these modules are not included in the bundle anyway due to `builtins: false`.

@substack I am happy to work on a PR for this if there is a slight change to get this improvement merged.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.