Skip to content
This repository was archived by the owner on Apr 19, 2021. It is now read-only.

Commit 2435c19

Browse files
committed
Browserify plugin for broccoli - 0.0.1
1 parent 5e52247 commit 2435c19

File tree

4 files changed

+115
-3
lines changed

4 files changed

+115
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1-
broccoli-browserify
2-
===================
1+
# brocolli-browserify
32

4-
Browserify plugin for Broccoli
3+
Use `require('modules')` in the browser with
4+
[browersify](https://https://github.com/substack/node-browserify)
5+
and [broccoli](https://github.com/joliss/broccoli)
6+
7+
## Install
8+
9+
```
10+
npm install --save-dev broccoli-browserify
11+
```
12+
13+
14+
## Example
15+
16+
```js
17+
var browserify = require('broccoli-browserify');
18+
tree = browserify(tree, options);
19+
```
20+
21+
22+
## API
23+
24+
### browserify(tree, options)
25+
26+
Options:
27+
28+
* `entries` : Array of files to be used as entry points
29+
* `browserify` : Options passed to the browserify constructor see: https://github.com/substack/node-browserify#var-b--browserifyfiles-or-opts
30+
* bundle: Options passed to browserify bundle method see: https://github.com/substack/node-browserify#bbundleopts-cb
31+
32+
## License
33+
34+
MIT © Gareth Andrew

lib/index.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var Transform = require('broccoli-transform');
2+
var RSVP = require('rsvp');
3+
var browserify = require('browserify')
4+
var mkdirp = require('mkdirp')
5+
var fs = require('fs')
6+
var path = require('path')
7+
8+
function BrowserifyFilter(inputTree, options) {
9+
if (!(this instanceof BrowserifyFilter)) {
10+
return new BrowserifyFilter(inputTree, options);
11+
}
12+
13+
this.inputTree = inputTree;
14+
this.options = options || {};
15+
}
16+
17+
BrowserifyFilter.prototype = Object.create(Transform.prototype);
18+
BrowserifyFilter.prototype.constructor = BrowserifyFilter;
19+
20+
BrowserifyFilter.prototype.transform = function (srcDir, destDir) {
21+
var options = this.options;
22+
var browserify_options = options.browserify || {};
23+
var bundle_options = options.bundle || {};
24+
25+
mkdirp.sync(path.join(destDir, path.dirname(options.outputFile)))
26+
27+
browserify_options.basedir = srcDir;
28+
var b = browserify(browserify_options);
29+
30+
for(var i=0; i < options.entries.length; i++){
31+
b.add(options.entries[i]);
32+
}
33+
34+
return new RSVP.Promise(function(resolve, reject) {
35+
b.bundle(bundle_options, function (err, data) {
36+
if (err) {
37+
return reject(err);
38+
}
39+
fs.writeFileSync(path.join(destDir, options.outputFile), data)
40+
41+
resolve(destDir);
42+
});
43+
}.bind(this));
44+
};
45+
46+
module.exports = BrowserifyFilter;
47+
48+

package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "broccoli-browserify",
3+
"version": "0.0.1",
4+
"description": "Browserify plugin for Broccoli",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"test": "jshint lib/*.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/gingerhendrix/broccoli-browserify"
12+
},
13+
"keywords": [
14+
"broccoli-plugin",
15+
"browserify"
16+
],
17+
"author": "Gareth Andrew",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/gingerhendrix/broccoli-browserify/issues"
21+
},
22+
"homepage": "https://github.com/gingerhendrix/broccoli-browserify",
23+
"dependencies": {
24+
"broccoli-transform": "^0.1.1",
25+
"rsvp": "^3.0.6",
26+
"browserify": "^3.31.2",
27+
"mkdirp": "^0.3.5",
28+
"broccoli": "^0.2.1"
29+
},
30+
"devDependencies": {
31+
"jshint": "^2.4.4"
32+
}
33+
}

0 commit comments

Comments
 (0)