Revert "Switched from browserify to pure-cjs bundler."
This reverts commit bff9731b66093239dc0408fb1d83df423925b6f9.
Ben Newman committed
Feb 3, 2014 at 19:05 UTC
9f1ed709d05286df519061cc34199c3e455cb200
2 files changed
+41
-16
grunt/tasks/browserify.js
+40
-15
@@ -1,6 +1,6 @@
1
'use strict';
2
3
-var cjs = require('pure-cjs');
3
+var browserify = require('browserify');
4
var grunt = require('grunt');
5
6
module.exports = function() {
@@ -18,26 +18,51 @@ module.exports = function() {
18
config.after = [config.after];
19
}
20
21
- // Extract options
21
+ // create the bundle we'll work with
22
+ var entries = grunt.file.expand(config.entries);
23
+ var bundle = browserify(entries);
24
+
25
+ // Make sure the things that need to be exposed are.
26
+ var requires = config.requires || {};
27
+ if (requires instanceof Array) {
28
+ grunt.file.expand({
29
+ nonull: true, // Keep IDs that don't expand to anything.
30
+ cwd: "src"
31
+ }, requires).forEach(function(name) {
32
+ bundle.require("./build/modules/" + name, {
33
+ expose: name.replace(/\.js$/i, "")
34
+ });
35
+ });
36
+ } else if (typeof requires === "object") {
37
+ Object.keys(requires).forEach(function(name) {
38
+ bundle.require(requires[name], { expose: name });
39
+ });
40
+ }
41
+
42
+ // Extract other options
43
var options = {
23
- input: config.entries[0],
24
- output: config.outfile,
25
- map: config.debug, // sourcemaps
26
- exports: config.standalone, // global
27
- transform: config.transforms,
28
- dryRun: true // we will write to disk ourselves
44
+ debug: config.debug, // sourcemaps
45
+ standalone: config.standalone // global
46
};
47
48
+ // TODO: make sure this works, test with this too
49
+ config.transforms.forEach(function(transform) {
50
+ bundle.transform({}, transform);
51
+ });
52
+
53
// Actually bundle it up
54
var _this = this;
33
- cjs.transform(options).then(function(result) {
34
- grunt.file.write(config.outfile, config.after.reduce(function(src, fn) {
35
- return fn.call(_this, src);
36
- }, result.code));
55
+ bundle.bundle(options, function(err, src) {
56
+ if (err) {
57
+ grunt.log.error(err);
58
+ done();
59
+ }
60
38
- done();
39
- }, function(err) {
40
- grunt.log.error(err);
61
+ config.after.forEach(function(fn) {
62
+ src = fn.call(_this, src);
63
+ });
64
+
65
+ grunt.file.write(config.outfile, src);
66
done();
67
});
68
};
package.json
+1
-1
@@ -39,6 +39,7 @@
39
},
40
"devDependencies": {
41
"benchmark": "~1.0.0",
42
+ "browserify": "~3.20.0",
43
"coverify": "~1.0.4",
44
"envify": "~1.0.1",
45
"es5-shim": "~2.3.0",
@@ -59,7 +60,6 @@
60
"phantomjs": "~1.9",
61
"platform": "~1.0.0",
62
"populist": "~0.1.6",
62
- "pure-cjs": "~1.8.0",
63
"recast": "~0.5.6",
64
"sauce-tunnel": "~1.1.0",
65
"semver": "~2.2.1",