exposify
v0.5.0
Published
browserify transform that exposes globals added via a script tag as modules so they can be required.
Downloads
101,438
Readme
exposify
browserify transform that exposes globals added via a script tag as modules so they can be required.
<!-- index.html -->
<head>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r61/three.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
[..]
// main.js
var $ = require('jquery')
, THREE = require('three')
console.log('THREE revision: ', THREE.REVISION);
console.log('jquery version: ', $().jquery);
Building via JavaScript
var browserify = require('browserify');
// configure what we want to expose
var exposeConfig = { expose: { jquery: '$', three: 'THREE' } };
browserify()
.require(require.resolve('./main'), { entry: true })
.transform('exposify', exposeConfig)
.bundle({ debug: true })
.pipe(fs.createWriteStream(path.join(__dirname, 'bundle.js'), 'utf8'))
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
generated with docme
License
MIT