Posts

Showing posts from October, 2018

Organize Loading JS Modules in Browserify Apps

Browserify has to be able to statically analyze all of the require statements at build time so it can know what files it needs to include in the bundle. That requires that  require  can only be used with a string literal in the source code. To organize loading js modules, there are many ways to do that. By the way,  Browserify   is a development tool that allows us to write node.js-style modules that compile for use in the browser. Just like node, we write our modules in separate files, exporting external methods and properties using the module.exports and exports variables. Organize Loading JS Modules in Browserify Apps My way is to make a lazy module loader which returns one object of modules that are needed to be instantiated one time only (Singleton Objects). This loader can be accessed in the global scope and it is very easy to use. Modules Loader Let’s assume that you have written two separated modules named LightComposer.js and TextTranslator.js. These two modules are needed in