Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

externalize

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

externalize

Create external Browserify bundles for lazy asynchronous loading

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

build status

externalize

Create external Browserify bundles for lazy asynchronous loading

Install

npm install externalize

API

The module exports a single function

externalize(
    <parent bundle or array of parent bundles>,
    <bundle or arrays of bundles to be externalized from the parent bundles>,
    <callback fucntion>
);

Example

Create two bundles where the second one is a subset of the parent and call externalize(parent, subset, callback) on them. It will do following:

  1. Moves all modules that are used in both to the parent one
  2. Removes those modules from the parent one that are explicitly requireable in the subset one
  3. It generally tries to do the "right thing"

in code:

var fs = require("fs");
var browserify = require("browserify");
var externalize = require("externalize");

// Parent bundle with an entry point
var parent = browserify("./index.js");

// Make subset bundle from external.js by making it explicitly requireable
var second = browserify().require("./external.js");

// Remove the subset bundle code from the parent
externalize(parent, subset, function(err) {
    if (err) throw err;

    // Write bundles to files after externalization
    parent.bundle.pipe(fs.createWriteStream("bundle/parent.js");
    second.bundle.pipe(fs.createWriteStream("bundle/second.js");
});

index.js

// would not work here because external.js is externalized to the subset bundle
// require("./external");

// Use any script loader to load the subset bundle to make the require work
// again
jQuery.getScript("bundle/second.js", function(){
    var value = require("./external");
    // Alerts: "external module: external module contents"
    alert("external module: " + value);
});

external.js:

module.exports = "external module contents";

Keywords

FAQs

Package last updated on 14 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc