GithubHelp home page GithubHelp logo

happy-ferret / global-wrap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from domenic/global-wrap

0.0 1.0 0.0 345 KB

Exposes your CommonJS-based libraries as a global.

License: Other

JavaScript 100.00%

global-wrap's Introduction

Global-ify Your CommonJS Library

This library will bundle up your CommonJS code and expose it as a property of the global object. It does so using browserify, so everything ends up in one file, even any native module shims you depend on.

In essence, this is a lighter-weight alternative to browserify's built-in standalone option; it only generates the global, omitting AMD support, and boils down the API into just what's necessary to complete this one task.

Usage

This package's main module's default export is a function that takes two arguments: some options, and a callback.

The options are:

  • main: the file path of your main module, which you want to expose as a global.
  • global: the name of the global you want to expose.
  • browserifyOptions: any browserify options you want to pass along, like noparse, builtins, detectGlobals, debug, etc.
  • tmpDir: the temporary directory to use. If this option is not specified the operating system's default directory for temp files will be used.

The callback will be called with either an error or a string containing JavaScript source. This JS source will, upon being loaded into a browser, create the specified global on self, whose value will be the same as if you'd done require(options.main). Thus, it's ready for inserting into your page as a <script> tag and use by other global-using scripts.

Here's an example:

var globalWrap = require("global-wrap");

globalWrap({
    main: "my-library.js",
    global: "myLib",
    browserifyOptions: { detectGlobals: false }
}, function (err, output) {
    // handle `err`, or write `output` to a `.js` file, or something.
});

global-wrap's People

Contributors

domenic avatar lpinca avatar

Watchers

 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.