Senin, 01 Juni 2015
browserify offline
Diposting oleh
Blogger
di
00.04
Label:
API JavaScript,
aplikasi,
browserify offline,
HTML5 kerangka,
Tak Berkategori
browser-side require() the node wayrequire('modules') in the browser
Use a node-style require() to organize your browser code and load modules installed by npm.
browserify will recursively analyze all the require() calls in your app in order to build a bundle you can serve up to the browser in a single <script> tag.
getting started
If you're new to browserify, check out the browserify handbook and the resources on browserify.org.
Check out browserify search to find browserify-compatible packages on npm.
example
Whip up a file, main.js with some require()s in it. You can use relative paths like './foo.js' and '../lib/bar.js' or module paths like 'gamma' that will search node_modules/ using node's module lookup algorithm.
var foo = require('./foo.js');
var bar = require('../lib/bar.js');
var gamma = require('gamma');
var elem = document.getElementById('result');
var x = foo(100) + bar('baz');
elem.textContent = gamma(x);
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 required.
To use this bundle, just toss a <script src="bundle.js"></script> into your html!
Go to Page
Downloads Package
How to Download & Install
Langganan:
Posting Komentar (Atom)

Tidak ada komentar:
Posting Komentar