npm.io
0.5.0 • Published 10 years ago

exposify

Licence
MIT
Version
0.5.0
Deps
5
Vulns
0
Weekly
0
Stars
63

exposify build status

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: '

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: '
 // setting from javascript
exposify.config = { jquery: '
 # setting from command line
EXPOSIFY_CONFIG='{ "jquery": "$", "three": "THREE" }' browserify -t exposify ...
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

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

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, 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 __INLINE_CODE_0__ environment variable:

__CODE_BLOCK_3__

Or using a Browserify transform option:

__CODE_BLOCK_4__

Or use browserify-shim which can configure exposify in __INLINE_CODE_1__ among other features.

Installation

__CODE_BLOCK_5__

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 __INLINE_CODE_2__ environment variable.

__CODE_BLOCK_6__ __CODE_BLOCK_7__ __CODE_BLOCK_8__
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, three: 'THREE' } });
__CODE_BLOCK_7__ __CODE_BLOCK_8__
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, 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 __INLINE_CODE_0__ environment variable:

__CODE_BLOCK_3__

Or using a Browserify transform option:

__CODE_BLOCK_4__

Or use browserify-shim which can configure exposify in __INLINE_CODE_1__ among other features.

Installation

__CODE_BLOCK_5__

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 __INLINE_CODE_2__ environment variable.

__CODE_BLOCK_6__ __CODE_BLOCK_7__ __CODE_BLOCK_8__
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, three: 'THREE' }; __CODE_BLOCK_8__
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, 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 __INLINE_CODE_0__ environment variable:

__CODE_BLOCK_3__

Or using a Browserify transform option:

__CODE_BLOCK_4__

Or use browserify-shim which can configure exposify in __INLINE_CODE_1__ among other features.

Installation

__CODE_BLOCK_5__

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 __INLINE_CODE_2__ environment variable.

__CODE_BLOCK_6__ __CODE_BLOCK_7__ __CODE_BLOCK_8__
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, three: 'THREE' } }); __CODE_BLOCK_7__ __CODE_BLOCK_8__ Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

, 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 __INLINE_CODE_0__ environment variable:

__CODE_BLOCK_3__

Or using a Browserify transform option:

__CODE_BLOCK_4__

Or use browserify-shim which can configure exposify in __INLINE_CODE_1__ among other features.

Installation

__CODE_BLOCK_5__

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 __INLINE_CODE_2__ environment variable.

__CODE_BLOCK_6__ __CODE_BLOCK_7__ __CODE_BLOCK_8__
Source:

exposify::expose

Exposes the expose function that operates on a string

Source:

exposify::filePattern

Regex pattern of files whose content is exposified

Source:

exposify(file, opts) → {TransformStream}

browserify transform which exposes globals as modules that can be required.

Parameters:
Name Type Argument Description
__INLINE_CODE_3__ string

file whose content is to be transformed

__INLINE_CODE_4__ Object <optional>

(exposify config), defaults to exposify.config or $EXPOSIFY_CONFIG

Source:
Returns:

transform that replaces require statements found in the code with global assigments

Type TransformStream

generated with docme

License

MIT

Keywords

browserifybrowserify-transformtransformexposewindowglobalrequireshim