externalize
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -133,3 +133,3 @@ | ||
module.exports = function(parents, externals, cb) { | ||
module.exports = function externalize(parents, externals, cb) { | ||
cb = once(cb); | ||
@@ -136,0 +136,0 @@ parents = [].concat(parents); |
{ | ||
"name": "externalize", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Create external Browserify bundles for lazy asynchronous loading", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,6 @@ [![build status](https://secure.travis-ci.org/epeli/browserify-externalize.png)](http://travis-ci.org/epeli/browserify-externalize) | ||
Introduction to asynchronous module loading with Browserify: | ||
<http://esa-matti.suuronen.org/blog/2013/04/15/asynchronous-module-loading-with-browserify/> | ||
## Install | ||
@@ -45,3 +49,3 @@ | ||
// Make subset bundle from external.js by making it explicitly requireable | ||
var second = browserify().require("./external.js"); | ||
var subset = browserify().require("./external.js"); | ||
@@ -53,16 +57,16 @@ // Remove the subset bundle code from the parent | ||
// Write bundles to files after externalization | ||
parent.bundle.pipe(fs.createWriteStream("bundle/parent.js"); | ||
second.bundle.pipe(fs.createWriteStream("bundle/second.js"); | ||
parent.bundle().pipe(fs.createWriteStream("bundle/parent.js")); | ||
subset.bundle().pipe(fs.createWriteStream("bundle/subset.js")); | ||
}); | ||
``` | ||
index.js | ||
index.js: | ||
```javascript | ||
// would not work here because external.js is externalized to the subset bundle | ||
// require("./external"); | ||
// Would not work here because external.js is externalized to the subset bundle | ||
// Use any script loader to load the subset bundle to make the require work | ||
// again | ||
jQuery.getScript("bundle/second.js", function(){ | ||
jQuery.getScript("bundle/subset.js", function(){ | ||
var value = require("./external"); | ||
@@ -80,2 +84,22 @@ // Alerts: "external module: external module contents" | ||
## Script loaders | ||
You need a script loader to load the external bundles. There is one in | ||
[jQuery][getscript]. If you don't use jQuery you can grab [$script.js][] | ||
from [npm][$script.js-npm] or implement your [own][modern] for modern browsers | ||
easily. | ||
Some others include: | ||
- [yepnope](http://yepnopejs.com/) | ||
- [head.js](http://headjs.com/) | ||
- [lab.js](http://labjs.com/) | ||
- [lazyload](https://github.com/rgrove/lazyload/) | ||
- [basket.js](http://addyosmani.github.io/basket.js/) | ||
[Browserify]: https://github.com/substack/node-browserify | ||
[getscript]: http://api.jquery.com/jQuery.getScript/ | ||
[$script.js]: http://dustindiaz.com/scriptjs | ||
[$script.js-npm]: https://npmjs.org/package/scriptjs | ||
[modern]: https://gist.github.com/epeli/5384178 | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16991
102