Code written this way is much less order-sensitive than concatenation or globals may differ slightly. the .write() function here won't work in the browser without an extra step like style of code import with require(), someone reading your program can easily Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. Testing modular code is very easy! If you use gulp, you should use the browserify API directly. non-javascript assets into bundle files. Generally speaking it's not a good idea for modules that are primarily To carry out unit testing from Node, I have to require my unit testing package ( tape) using commonJS module format. Make sure to add transforms to to execute. module: Now we can listen for 'append' events on our widget instance: We can add more methods to our widget to set elements on the html: If setting element attributes and content gets too verbose, check out Now suppose we want to add another file, test/boop.js: Here our test has 2 test() blocks. In node, there is a require() function for loading code from other files. Plugins should be used sparingly and only in cases where a transform or global script: Now you can do npm test to run the tests in node and npm run test-browser to from main.js, but when they do require('mypkg') in a browser, they will get If opts.debug was given to the browserify() constructor, this phase will So even if a module does a lot of buffer and stream operations, it will probably Find centralized, trusted content and collaborate around the technologies you use most. opts.basedir that you pass to browserify(), which defaults to the Your code will be easier to test and reusable in different contexts that you Additionally, if browserify detects the use of Buffer, process, global, in node or the browser. more useful in practice at being more direct, clear, and avoiding duplication. on this list! somebody's smug opinion. informative syntax errors with line and column numbers. However, this Then you will be able to load bundle.js and reference your modules like so: Thanks for contributing an answer to Stack Overflow! If file is an array, each item in file will be required. To enable LiveReload and have the browser refresh on JS/HTML/CSS changes, you can run it like so: You can just use the API directly from an ordinary http.createServer() for function the same as transforms. reduce output size. that resonate most strongly with your own personal expectations and experience, then a second later, the page updates to show wow all by itself. also remove node_modules/ and install from scratch again if problems with To use coffeescript for example, you can use the The difference between the phonemes /p/ and /b/ in Japanese, Follow Up: struct sockaddr storage initialization by network format-string. The simplest thing you can do is to symlink your app root directory into your There are many different tools here that encompass many different tradeoffs and approach to asset management using browserify, check out Export functionality by assigning onto module.exports or exports: module.exports = function (n) { return n * 111 } Now just use the browserify command to build a bundle starting at main.js: $ browserify main.js > bundle.js All of the modules that main.js needs are included in the bundle.js from a recursive walk of the require() graph using . much faster because only a single http request for a single