MIT License
This is a small example project or project template for npm modules that are supposed to work in Node.js and in the browser.
When writing JavaScript code that is ought to work in Node.js as well as in the browser, there are a couple of questions that need to be answered:
As of now, this issues are not trivially solved. However, there are already quite a few approaches to tackle these problems. One option is to add some boilerplate code to each module to make it compatible with CommonJS and AMD. amdefine works in a similar fashion. Another approach is browserify. In the future, this problem might be solved by the module system that comes with Harmony/ES6. Since ES6 is not there yet and major browser support will not be available for quite some time, this is not relevant today (or maybe it is, with the help of this transpiler).
The fact that there are various solutions to the problem doesn't make it easier. When starting out with your first cross platform npm module, the options at hand might seem confusing and getting everything set up is still way more complicated than it should be.
This project template uses browserify to convert the CommonJS code to browser compatible code. It comes with a rather complete setup, including:
minimatch
, but the choice was arbitrary, it's just an example),util
, in this case),browser
property (making browserify use substitutes instead of the original node dependencies)This infrastructure is a good starting point for writing cross platform (Node.js and browser) JavaScript code.
Remark: The Gruntfile uses grunt-browserify to browserify the module and the tests and it actually kicks off three browserify builds. For a small module like this, the turnaround time is still good enought. For a larger module, watchify might be a better (faster) alternative.
MIT