diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index 396c8eab244dd..f0ad28dfa13c9 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -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 = @@ -69,7 +69,7 @@ var basic = { var min = _.merge({}, basic, { outfile: './build/react.min.js', debug: false, - transforms: [envify({NODE_ENV: 'production'})], + transforms: [envify({NODE_ENV: 'production'}), uglifyify], after: [minify, bannerify] }); @@ -80,7 +80,6 @@ var transformer = { outfile: './build/JSXTransformer.js', debug: false, standalone: 'JSXTransformer', - transforms: [deamdify], after: [simpleBannerify] }; @@ -99,7 +98,7 @@ var addons = { var addonsMin = _.merge({}, addons, { outfile: './build/react-with-addons.min.js', debug: false, - transforms: [envify({NODE_ENV: 'production'})], + transforms: [envify({NODE_ENV: 'production'}), uglifyify], after: [minify, bannerify] }); diff --git a/grunt/tasks/browserify.js b/grunt/tasks/browserify.js index 9a0eea744bcb1..e36c545e17bf0 100644 --- a/grunt/tasks/browserify.js +++ b/grunt/tasks/browserify.js @@ -1,6 +1,6 @@ 'use strict'; -var cjs = require('pure-cjs'); +var browserify = require('browserify'); var grunt = require('grunt'); module.exports = function() { @@ -18,26 +18,51 @@ module.exports = function() { config.after = [config.after]; } - // Extract options + // 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 var options = { - 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 + debug: config.debug, // sourcemaps + standalone: config.standalone // global }; + // TODO: make sure this works, test with this too + config.transforms.forEach(function(transform) { + bundle.transform({}, transform); + }); + // Actually bundle it up var _this = this; - cjs.transform(options).then(function(result) { - grunt.file.write(config.outfile, config.after.reduce(function(src, fn) { - return fn.call(_this, src); - }, result.code)); + bundle.bundle(options, function(err, src) { + if (err) { + grunt.log.error(err); + done(); + } - done(); - }, function(err) { - grunt.log.error(err); + config.after.forEach(function(fn) { + src = fn.call(_this, src); + }); + + grunt.file.write(config.outfile, src); done(); }); }; diff --git a/package.json b/package.json index 69cd50e477d1c..1d89f67fa7fbc 100644 --- a/package.json +++ b/package.json @@ -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", @@ -60,7 +60,6 @@ "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", diff --git a/vendor/browser-transforms.js b/vendor/browser-transforms.js index b0e61c6bb7691..701693c34a7cf 100644 --- a/vendor/browser-transforms.js +++ b/vendor/browser-transforms.js @@ -20,6 +20,7 @@ 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'); @@ -96,10 +97,6 @@ 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"; @@ -114,7 +111,7 @@ var transformCode = function(code, source) { return ( transformed.code + '//# sourceMappingURL=data:application/json;base64,' + - btoa(unescape(encodeURIComponent(JSON.stringify(map)))) + buffer.Buffer(JSON.stringify(map)).toString('base64') ); } else { return code;