Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Last active October 22, 2015 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirbysayshi/8d848e50f89d09555460 to your computer and use it in GitHub Desktop.
Save kirbysayshi/8d848e50f89d09555460 to your computer and use it in GitHub Desktop.
browserify for node example
module.exports = function () {
return 'another';
}
var browserify = require('browserify');
var b = browserify({
builtins: false,
commondir: false,
browserField: false,
insertGlobalVars: ['__filename', '__dirname']
});
b.add('./index.js');
b.bundle(function (err, data) {
process.stdout.write(data.toString());
});
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = function () {
return 'another';
}
},{}],2:[function(require,module,exports){
(function (__filename,__dirname){
var events = require('events');
var vm = require('vm');
var another = require('./another');
console.log(another());
console.log('__filename', __filename);
console.log('__dirname', __dirname);
}).call(this,"/private/tmp/browserify-for-node/index.js","/private/tmp/browserify-for-node")
},{"./another":1,"events":undefined,"vm":undefined}]},{},[2]);
var events = require('events');
var vm = require('vm');
var another = require('./another');
console.log(another());
console.log('__filename', __filename);
console.log('__dirname', __dirname);
{
"name": "browserify-for-node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "node builder.js > bundle.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"browserify": "^11.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment