1 | # bromote
|
2 |
|
3 | Tool to setup and require remote scripts with browserify.
|
4 |
|
5 | ### Server Side
|
6 |
|
7 | ```js
|
8 | var browserify = require('browserify');
|
9 | var bromote = require('bromote');
|
10 | var PassThrough = require('stream').PassThrough;
|
11 |
|
12 | var remote =
|
13 | { jquery:
|
14 | { exports: '$',
|
15 | url: 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' },
|
16 | backbone:
|
17 | { deps: { jquery: '$', underscore: '_' },
|
18 | exports: 'Backbone',
|
19 | url: 'http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js' },
|
20 | underscore:
|
21 | { exports: '_',
|
22 | url: 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js' } };
|
23 |
|
24 | var passThrough = new PassThrough();
|
25 | var bify = browserify();
|
26 |
|
27 | bromote(bify, remote, function (err) {
|
28 | if (err) return console.error(err);
|
29 |
|
30 | bify
|
31 | .add('./main.js', { entry: true })
|
32 | .bundle()
|
33 | .pipe(passThrough);
|
34 | });
|
35 | return passThrough;
|
36 | ```
|
37 |
|
38 | ### Client Side
|
39 |
|
40 | ```js
|
41 | bromote.backbone(function (backbone) {
|
42 | console.log(backbone.$().jquery); // => '1.7.1'
|
43 | });
|
44 |
|
45 | bromote.jquery(function ($) {
|
46 | console.log($().jquery); // => '1.7.1'
|
47 | })
|
48 | ```
|
49 |
|
50 | Example derived from [this test](https://github.com/thlorenz/bromote/tree/master/test/remote-backbone-jquery-underscore)
|
51 |
|
52 | For more examples see [examples](https://github.com/thlorenz/bromote/tree/master/examples) and [tests](https://github.com/thlorenz/bromote/tree/master/test).
|
53 |
|
54 | ## Disclaimer
|
55 |
|
56 | Since you are already using browserify and thus can pull in modules via npm in a version controlled manner, **you better
|
57 | have a damn good reason to load scripts from a url**.
|
58 |
|
59 | You loose versioning and are opening your app up to lots of unknowns. **Bad things will happen!**
|
60 |
|
61 | If any of the scripts pulled in via a url has a bug, it could potentially crash your app. Since you are loading it
|
62 | dynamically, you have no control over when that could happen, i.e. it the script could change months after you deployed
|
63 | your app.
|
64 |
|
65 | So in general **please don't do this**.
|
66 |
|
67 | ## Why bromote then?
|
68 |
|
69 | I created bromote to allow people to still use browserify, even if they find themselves in a situation where they are
|
70 | forced to load scripts from urls for whatever reason that is out of their control.
|
71 |
|
72 | ## Installation
|
73 |
|
74 | npm install bromote
|
75 |
|
76 | ## Features
|
77 |
|
78 | - load dependencies from any url
|
79 | - you may use bromote to load external browserify bundles **on demand**
|
80 | - bromote properly resolves and loads nested dependencies in correct order (see example)
|
81 |
|
82 | ## API
|
83 |
|
84 | ### Server side: ***bromote(bify, remote, cb)***
|
85 | ```
|
86 | /**
|
87 | * Generates all remote loaders and adds them to browserify instance if it is given.
|
88 | * Calls back with paths to generated loaders.
|
89 | *
|
90 | * @name exports
|
91 | * @function
|
92 | * @param bify {Object} browserify instance (optional) but recommended
|
93 | * @param remote {Object} hashtable containing information about remote scripts for which to generate and add loaders
|
94 | * @param cb {Function} called back with paths to generated loaders
|
95 | */
|
96 | ```
|
97 |
|
98 | ### Client side: ***bromote.foo(function (foo) { ... })***
|
99 |
|
100 | Assuming that `foo` was included as a remote server side, this will resolve it from the remote url and call back with
|
101 | its export once it is loaded.
|
102 |
|
103 | ## License
|
104 |
|
105 | MIT
|