Version1 /
NodeBundlingInstructionsWhy Bundle?Many Node modules are fully compatible with accessors because they consist of pure javascript with no Node dependencies. To convert a Node module to an accessor module when the Node module consists entirely of a single "ModuleName.js" file, simply copy "ModuleName.js" into the accessor modules directory. If the Node module has no Node.js dependencies, you can now require it an accessor with:
However some complex Node modules are built with more than just one "ModuleName.js" file. Sometimes a Node module has a 'lib' directory containing multiple "library.js" files which are in turn required by "ModuleName.js". A node module might also have dependencies on other Node modules. Even though the entire complex Node module might be compatible with accessors, it could get very confusing to copy 30 javascript files into the accessor modules directory. This is especially true when the main entry point for a Node module (eg. "Main.js") has a different name than the Node module itself. Node's module loading system is capable of resolving such an inconsistency by parsing the package.json file in a Node module, but you would have to fix the names manually when copying them over to the accessors directory. How to BundleWhile you could copy the many files of a complex Node module over to the accessor module directory and manually resolve the naming inconsistencies, browserify can do most of the work. Browserify automatically combines a full dependency graph of Node modules into a single "Bundle.js" file by recursively following require statements in the code. With a few small modifications, the output "Bundle.js" can be copied to the accessors modules directory in a few simple steps.
|