exposify
browserify transform that exposes globals added via a script tag as modules so they can be required.
<!-- index.html --> [..]
// main.jsvar $ = THREE = console;console;
Building via JavaScript
var browserify = ; // configure what we want to exposevar exposeConfig = expose: jquery: '$' three: 'THREE' ;
Building via Commandline
Using the EXPOSIFY_CONFIG
environment variable:
EXPOSIFY_CONFIG='{ "jquery": "$", "three": "THREE" }' browserify --debug -t exposify main.js > bundle.js
Or using a Browserify transform option:
browserify --debug -t [ exposify --expose [ --jquery $ --three THREE ] ] main.js > bundle.js
Or use browserify-shim which can configure exposify in package.json
among other features.
Installation
npm install exposify
API
-
exposify::config
-
The config which is used by exposify to determine which require statemtents to replace and how. You need to set this or provide it via the
EXPOSIFY_CONFIG
environment variable.var b = browserify(); // setting via transform argument b.transform('exposify', { expose: { jquery: '$', three: 'THREE' } });
// setting from javascript exposify.config = { jquery: '$', three: 'THREE' };
# setting from command line EXPOSIFY_CONFIG='{ "jquery": "$", "three": "THREE" }' browserify -t exposify ...
-
exposify::expose
-
Exposes the expose function that operates on a string
-
exposify::filePattern
-
Regex pattern of files whose content is exposified
-
exposify(file, opts) → {TransformStream}
-
browserify transform which exposes globals as modules that can be required.
Parameters:
Name Type Argument Description file
string file whose content is to be transformed
opts
Object <optional>
(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG
Returns:
transform that replaces require statements found in the code with global assigments
- Type
- TransformStream
generated with docme
License
MIT