From bff9731b66093239dc0408fb1d83df423925b6f9 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 31 Jan 2014 18:25:09 +0200 Subject: [PATCH 1/3] Switched from browserify to pure-cjs bundler. --- grunt/tasks/browserify.js | 55 +++++++++++---------------------------- package.json | 2 +- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/grunt/tasks/browserify.js b/grunt/tasks/browserify.js index e36c545e17bf0..9a0eea744bcb1 100644 --- a/grunt/tasks/browserify.js +++ b/grunt/tasks/browserify.js @@ -1,6 +1,6 @@ 'use strict'; -var browserify = require('browserify'); +var cjs = require('pure-cjs'); var grunt = require('grunt'); module.exports = function() { @@ -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(); }); }; diff --git a/package.json b/package.json index 1d89f67fa7fbc..21d9b71b8cc40 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ }, "devDependencies": { "benchmark": "~1.0.0", - "browserify": "~3.20.0", "coverify": "~1.0.4", "envify": "~1.0.1", "es5-shim": "~2.3.0", @@ -60,6 +59,7 @@ "phantomjs": "~1.9", "platform": "~1.0.0", "populist": "~0.1.6", + "pure-cjs": "~1.8.0", "recast": "~0.5.6", "sauce-tunnel": "~1.1.0", "semver": "~2.2.1", From f1b7db9aef57d5b2a9264b51e4303540772f847f Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 31 Jan 2014 21:53:08 +0200 Subject: [PATCH 2/3] More optimizations and fix for JSXTransformer build * Dropped dependency on emulation of Node.js native modules. * Added deamdify step for JSXTransformer build. --- grunt/config/browserify.js | 2 ++ package.json | 3 ++- vendor/browser-transforms.js | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index f0ad28dfa13c9..6c63ac5796b71 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -3,6 +3,7 @@ 'use strict'; +var deamdify = require('deamdify'); var envify = require('envify/custom'); var grunt = require('grunt'); var UglifyJS = require('uglify-js'); @@ -80,6 +81,7 @@ var transformer = { outfile: './build/JSXTransformer.js', debug: false, standalone: 'JSXTransformer', + transforms: [deamdify], after: [simpleBannerify] }; diff --git a/package.json b/package.json index 21d9b71b8cc40..69cd50e477d1c 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "devDependencies": { "benchmark": "~1.0.0", "coverify": "~1.0.4", + "deamdify": "~0.1.1", "envify": "~1.0.1", "es5-shim": "~2.3.0", "grunt": "~0.4.2", @@ -59,7 +60,7 @@ "phantomjs": "~1.9", "platform": "~1.0.0", "populist": "~0.1.6", - "pure-cjs": "~1.8.0", + "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 701693c34a7cf..b0e61c6bb7691 100644 --- a/vendor/browser-transforms.js +++ b/vendor/browser-transforms.js @@ -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'); @@ -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"; @@ -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; From 86373d924cd5f5808e3da72ceb2bf171bc9142f0 Mon Sep 17 00:00:00 2001 From: azure provisioned user Date: Mon, 3 Feb 2014 22:06:38 +0000 Subject: [PATCH 3/3] Removed redundant uglification Removed uglification for separate files since it significantly slowed down build (browserify:min became 26 sec instead of 110, same for :addonsMin) while gave economy in ~70 bytes for min+gz version. --- grunt/config/browserify.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/grunt/config/browserify.js b/grunt/config/browserify.js index 6c63ac5796b71..396c8eab244dd 100644 --- a/grunt/config/browserify.js +++ b/grunt/config/browserify.js @@ -7,7 +7,6 @@ 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 = @@ -70,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] }); @@ -100,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] });