Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched from browserify to pure-cjs builder #1002

Merged
merged 3 commits into from
Feb 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions grunt/config/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

'use strict';

var deamdify = require('deamdify');
var envify = require('envify/custom');
var grunt = require('grunt');
var UglifyJS = require('uglify-js');
var uglifyify = require('uglifyify');
var _ = require('lodash');

var SIMPLE_TEMPLATE =
Expand Down Expand Up @@ -69,7 +69,7 @@ var basic = {
var min = _.merge({}, basic, {
outfile: './build/react.min.js',
debug: false,
transforms: [envify({NODE_ENV: 'production'}), uglifyify],
transforms: [envify({NODE_ENV: 'production'})],
after: [minify, bannerify]
});

Expand All @@ -80,6 +80,7 @@ var transformer = {
outfile: './build/JSXTransformer.js',
debug: false,
standalone: 'JSXTransformer',
transforms: [deamdify],
after: [simpleBannerify]
};

Expand All @@ -98,7 +99,7 @@ var addons = {
var addonsMin = _.merge({}, addons, {
outfile: './build/react-with-addons.min.js',
debug: false,
transforms: [envify({NODE_ENV: 'production'}), uglifyify],
transforms: [envify({NODE_ENV: 'production'})],
after: [minify, bannerify]
});

Expand Down
55 changes: 15 additions & 40 deletions grunt/tasks/browserify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var browserify = require('browserify');
var cjs = require('pure-cjs');
var grunt = require('grunt');

module.exports = function() {
Expand All @@ -18,51 +18,26 @@ module.exports = function() {
config.after = [config.after];
}

// create the bundle we'll work with
var entries = grunt.file.expand(config.entries);
var bundle = browserify(entries);

// Make sure the things that need to be exposed are.
var requires = config.requires || {};
if (requires instanceof Array) {
grunt.file.expand({
nonull: true, // Keep IDs that don't expand to anything.
cwd: "src"
}, requires).forEach(function(name) {
bundle.require("./build/modules/" + name, {
expose: name.replace(/\.js$/i, "")
});
});
} else if (typeof requires === "object") {
Object.keys(requires).forEach(function(name) {
bundle.require(requires[name], { expose: name });
});
}

// Extract other options
// Extract options
var options = {
debug: config.debug, // sourcemaps
standalone: config.standalone // global
input: config.entries[0],
output: config.outfile,
map: config.debug, // sourcemaps
exports: config.standalone, // global
transform: config.transforms,
dryRun: true // we will write to disk ourselves
};

// TODO: make sure this works, test with this too
config.transforms.forEach(function(transform) {
bundle.transform({}, transform);
});

// Actually bundle it up
var _this = this;
bundle.bundle(options, function(err, src) {
if (err) {
grunt.log.error(err);
done();
}

config.after.forEach(function(fn) {
src = fn.call(_this, src);
});
cjs.transform(options).then(function(result) {
grunt.file.write(config.outfile, config.after.reduce(function(src, fn) {
return fn.call(_this, src);
}, result.code));

grunt.file.write(config.outfile, src);
done();
}, function(err) {
grunt.log.error(err);
done();
});
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
},
"devDependencies": {
"benchmark": "~1.0.0",
"browserify": "~3.20.0",
"coverify": "~1.0.4",
"deamdify": "~0.1.1",
"envify": "~1.0.1",
"es5-shim": "~2.3.0",
"grunt": "~0.4.2",
Expand All @@ -60,6 +60,7 @@
"phantomjs": "~1.9",
"platform": "~1.0.0",
"populist": "~0.1.6",
"pure-cjs": "~1.8.3",
"recast": "~0.5.6",
"sauce-tunnel": "~1.1.0",
"semver": "~2.2.1",
Expand Down
7 changes: 5 additions & 2 deletions vendor/browser-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
var runScripts;
var headEl;

var buffer = require('buffer');
var transform = require('jstransform').transform;
var visitors = require('./fbtransform/visitors').transformVisitors;
var docblock = require('jstransform/src/docblock');
Expand Down Expand Up @@ -97,6 +96,10 @@ var transformCode = function(code, source) {
throw e;
}

if (typeof btoa === 'undefined') {
return transformed.code;
}

var map = transformed.sourceMap.toJSON();
if (source == null) {
source = "Inline JSX script";
Expand All @@ -111,7 +114,7 @@ var transformCode = function(code, source) {
return (
transformed.code +
'//# sourceMappingURL=data:application/json;base64,' +
buffer.Buffer(JSON.stringify(map)).toString('base64')
btoa(unescape(encodeURIComponent(JSON.stringify(map))))
);
} else {
return code;
Expand Down