Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle node.js apps to a single file with Browserify

I'd like to distribute my node.js app as a single js file. The application is really simple, but it depends on a few libraries.

Browserify seems to bundle the npm dependencies nicely. However the app also depends on the fs built-in file system library and unfortunately its signatures doesn't seem to be loaded. For instance the following code gives undefined is not a function error.

var fs = require('fs')
fs.readFileSync(file, 'utf8');

I understand that main purpose of Browserify is to bring CommonJs based apps to the browser. But I wonder if there is any way to make the compiler fall back to the default require global function for built-in libraries.

like image 913
tamasf Avatar asked Dec 23 '14 16:12

tamasf


1 Answers

After going through all options it turned out that the --bare switch satisfies my requirement.

browserify --bare
like image 86
tamasf Avatar answered Nov 02 '22 21:11

tamasf