Skip to content

Instantly share code, notes, and snippets.

@skopp
Last active December 15, 2015 16:19
Show Gist options
  • Save skopp/5288092 to your computer and use it in GitHub Desktop.
Save skopp/5288092 to your computer and use it in GitHub Desktop.
Bundling Base64 img with brfs
substack : tweet-button $ browserify -t brfs main.js
;(function(e,t,n,r){function i(r){if(!n[r]){if(!t[r]){if(e)return e(r);throw new Error("Cannot find module '"+r+"'")}var s=n[r]={exports:{}};t[r][0](function(e){var n=t[r][1][e];return i(n?n:e)},s,s.exports)}return n[r].exports}for(var s=0;s<r.length;s++)i(r[s]);return i})(typeof require!=="undefined"&&require,{1:[function(require,module,exports){var fs = require('fs');
var img = "iVBORw0KGgoAAAANSUhEUgAAACwAAAAlCAYAAAA5iwvJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAJpAAACaQBOMpC7QAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAQeSURBVFiFzdhZqFVVHMfxz7rd5nk12ZxCIhVSSUmRTUQ0oBVbISqLkF6aKEgKekkqBCNKKOih6S0ytgVRkkSWNFBREEVJoyKSKe7mAVNXD2ufOvd47jnnds699YXDPvz3f63922sv/sMKKSUTRSirYVyMOdiKZ3AU3sQPqYi/dBm7Y3iChJ6KG2qh3+PE+tZvuAPP48JQVnekIj7WMvYQLMBwKuJ9obHCoawW4oNUxNcGKPRwLMNZo7g8h3n1SxxY25ZhFabiPEzH2zg/FfHPZsEfyW8+LxXx+QGInYYVOK6D23oc3WWqNTgnFXEThJSSUFZHYEPt8AcuSkV8ow+xU/A+4r+do0nseamIG0NZ7YM4VN9o/mR7YEUoq0v7eND1+he7A69jSSirD/EDZjZWeBLOxY2YVQ/YhgexOBXxx7E8KZTVV5jSp+BmEm5PRVzaWOHZcog5DOtq2zDuxJehrBaGstq7R7FTByx2K65MRVwKDcEb6+tUHNsy4GAswcehrE7u4QH7DUJlzTbMTkVc1jA0BK/pYfBkXBHKanEoq2M6+PX0JXrknVTElc2GIUhF/AKre5jgeNyFp0JZLQhldUYoq6EWn60DkZpZ22poznSP4OwuE8yrr9/i8fr/1lBW6+W9vw6b+tM4gkmthtBcS4Syuk2ODK2r1kzCL9h3gMJG4+NUxOnNhqFQVnuFsloZympWKuLDuATfdZgkGH+x2/GJnLpHMJSK+BuOxOpQVt/hfjm3/5fsgpOwa+uNxh5ejhNwaP37v/BSq6GxVx/FzxOrpSub5XpkBI2wthGLJlpRF1akIu5oNTZHg4fwwsTp6cpO24EmwfXbXI2XJ0pRB7bhlXY3RsTbOmLMxt0YU4U2YN4arUIMozWhoaz2x3x5b/db23Zjsxzbl+N3vJyKuLyd405NaCirM+U0vRmn+afXGk/W4Fk8gEWjiaWNYLwrt0kXjo+2tszC13JZ8Gknx51qhlTE7bhWTo8TyXX4KRXxxU5ObYucVMQv8cR4qOrABjzZzalTVXaT/Il2Ct7jwHZclYq4pZvjqFHib4eyOh234nKD7SaauScVsadM21Xw3465CT0ZM+Qeb/d/LW8kq3BBuzTcjk5bYgSpiL9iT9xicGJfxZxexdI+rI0glNVkOWXPl7vqQfEcrklFHFMP2C5xBJwidx6XYqbcZYyF1GHMr7gXD4xlZRsM1+eut9Qij8E0+UClH9biIDndNgt/BgtTETe0G9QLjaOqQ+Uifm4/KpvYgKXyai6Rs9jNqYi9HCV0pLVrnls/YHKP4zdq04rXzJDbrXX4vM6gfdM2rIWymo7L5BPzGUbfj2/jALkfhC1yW/Menk5F/GYQIrsKHuFQVnvKJz5T62uUw9pu+AafyQnlvVTErwYtsJW/ALm+T3KNhd+aAAAAAElFTkSuQmCC";
console.log(img);
},{"fs":2}],2:[function(require,module,exports){// nothing to see here... no file methods for the browser
},{}]},{},[1]);
var fs = require('fs');
var img = fs.readFileSync(__dirname + '/twitter.png', 'base64');
console.log(img);
@skopp
Copy link
Author

skopp commented Apr 1, 2013

https://gist.github.com/substack/5095568/#comment-792703

to clarify what this does:

if you specify -t brfs it will use the brfs module (which you have to install) as a browserify 'transform' which in this
case will automatically replace any fs.readFileSync calls with the base64 encoded string instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment