Go browserify--using node. js for modular loading of JS

Source: Internet
Author: User

Original address: Http://www.oschina.net/p/browserify

Browserify allows you to organize your browser-side JavaScript code in a way that is similar to Node's require (), which allows front-end JavaScript to directly use some of the libraries that node NPM installs.

Installation:

Install -G browserify

Example

This is the content of Main.js, which uses require () to load libraries and files as normal Nodejs programs:

 var foo = require ('./foo.js '); var bar = require ('.. /lib/bar.js '); var gamma = require (' gamma '); var elem = document.getElementById (' result '); var x = foo (+) + bar (' baz '= gamma (x);

How to export:

function return n * 111}

Compile with browserify:

$ browserify main.js > Bundle.js

All other files required by Main.js are now compiled into bundle.js, including many layers of require () that are recursively compiled together.

Compiled JS can be used directly to the browser.

<src= "Bundle.js"></script>

Go browserify--using node. js for modular loading of JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.