Posted on February 5, 2014 by Paul
and instantly have access to everything was exported in the required module ?
this gives us a callback function that will fire once the required module is loaded. But, what if you want something even simpler, something that looks more like the Node.js syntax, or Lua’s require, or other languages ? Enter Browserify!
You can install browserify and watchify with the NodeJS manager npm. Assuming you have installed NodeJS on your computer, open a Terminal (for Windows you could use a Command Prompt, just remove the sudo from both lines) and write:
Please note the highlighted line from above, this will let us use the object Person in a different file. Save the above file as person.js.
save the above as main.js. We can compile the above two files using browserify through watchify:
Let’s include bundle.js in a dummy html file:
Now, add an extra line to main.js and save the file:
the output file, bundle.js, will be generated for you, if you refresh the test.html in your browser, you should see:
and the result, assuming LivePage was enabled:
The above will enable source maps for your input files.
If you are interested in Node.js, this is a good book Node.js 8 the Right Way by J. R. Wilson: