Giter Site home page Giter Site logo

prayagverma / exposify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thlorenz/exposify

0.0 2.0 0.0 336 KB

browserify transform that exposes globals added via a script tag as modules so they can be required.

License: MIT License

JavaScript 86.63% Shell 1.92% HTML 11.44%

exposify's Introduction

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

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 ...
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

exposify's People

Contributors

thlorenz avatar bendrucker avatar jeswin avatar cuth avatar levacic avatar pdufour avatar

Watchers

Prayag Verma  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.