Julián Duque
Developer and Educator
Mejores prácticas y optimización
Julián David Duque
Developer by Passion
Engineer at Nodejitsu
$ npm init
$ npm install <package>
$ npm search <package>
$ npm list
$ npm install -g bower
$ bower init
$ bower install <package>
$ bower search <package>
$ bower list [--paths]
// Definition
var MyModule = function() { .. };
// Require (Not needed, its global!)
// Use
MyModule();
Asynchronous Module Definition
// Definition
define(['my-dependency'], function(MyDependency) { return function() {}; };
// Require & Userequire(['my-dependency'], function(MyDependency) { MyDependency(); });
// Definition
module.exports = function() {};
// Require
var MyDependency = require('my-dependency');
// Use
MyDependency();
(function (root, factory) {
if (typeof exports === 'object') {
// CommonJS
module.exports = factory(require('b'));
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['b'], function (b) {
return (root.returnExportsGlobal = factory(b));
});
} else {
// Global Variables
root.returnExportsGlobal = factory(root.b);
}
}(this, function (b) {
// Your actual module
return {};
}));
WAT???
RequireJS (AMD)
Browserify (CommonJS)
By Julián Duque
Mejores prácticas y optimización