CodeFest
<script src="lib/vendor/jquery-2.1.0.js"></script>
<script src="main.js"></script>
<script src="lib/vendor/jquery-2.1.0.js"></script>
<script src="lib/vendor/jquery-plugin-for-maps.js"></script>
<script src="main.js"></script>
<script src="google-analytics.js"></script>
<script src="chartbeat.js"></script>
<script src="lib/vendor/jquery-2.1.0.js"></script>
<script src="lib/vendor/jquery-plugin-for-maps.js"></script>
<script src="main.js"></script>
<script src="lib/vendor/jquery-plugin-for-making-carousels.js"></script>
<script src="main-for-landing-page.js"></script>
<script src="google-analytics.js"></script>
<script src="chartbeat.js"></script>
<script src="lib/vendor/jquery-2.1.0.js"></script>
<script src="lib/vendor/jquery-plugin-for-maps.js"></script>
<script src="main.js"></script>
<script src="lib/vendor/jquery-plugin-for-making-carousels.js"></script>
<script src="main-for-landing-page.js"></script>
<script src="main-for-landing-page2.js"></script>
<script src="lib/vendor/jquery-plugin-for-making-datepickers.js"></script>
<script src="main-for-landing-page3.js"></script>
<script src="main-for-landing-page4.js"></script>
<script src="lib/vendor/jquery-plugin-for-making-modals.js"></script>
<script src="main-for-landing-page5.js"></script>
<script src="main-for-landing-page6.js"></script>
<script src="lib/vendor/jquery-plugin-for-making-autocompletes.js"></script>
<script src="main-for-landing-page7.js"></script>
<script src="main-for-landing-page8.js"></script>
AMD
1. // point.js
2. define("point", function() {
3. function Point(x, y) {
4. this.x = x;
5. this.y = y;
6. }
7. return Point;
8. });
9.
10. // myapp.js
11. define("myapp", ["point"], function(Point) {
12. var origin = new Point(0, 0);
13. console.log(origin);
14. });
CommonJS
1. // point.js
2. function Point(x, y) {
3. this.x = x;
4. this.y = y;
5. }
6. module.exports = Point;
7.
8. // myapp.js
9. var Point = require("./point");
10. var origin = new Point(0, 0);
11. console.log(origin);
UMD
// point.js
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(function () {
return (root.returnExportsGlobal = factory());
});
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.returnExportsGlobal = factory();
}
}(this, function () {
function Point(x, y) {
this.x = x;
this.y = y;
}
return Point;
}));
Native JavaScript Modules - ES6
1. // point.js
2. function Point(x, y) {
3. this.x = x;
4. this.y = y;
5. }
6. export default Point;
7.
8. // myapp.js
9. import Point from "point";
10. var origin = new Point(0, 0);
11. console.log(origin);
requirejs.config({
paths: {
"jquery": "bower_components/jquery/jquery-2.1.0.min.js"
"ember": "bower_components/ember/ember.js"
},
shim: {
"ember": {
deps: ["jquery"],
exports: "Ember"
}
}
});
define("myapp", ["ember", "jquery"], function(Ember, jQuery) {
//use Ember and jQuery
});
> npm install euclidean-distance;
> node r.js -o name=myapp out=myapp.build.js;
//myapp.js
define("myapp", ["point", "euclidean-distance"], function(Point, d) {
var origin = new Point(0, 0);
var otherPoint = new Point(1, 1);
var distance = d(origin, otherPoint);
console.log(distance); //1
});
require
-ing
> browserify -t deamdify -e entry.js > main.js
//entry.js
var moduleWrittenInAmd = require("./vendor/amdModule.js");
useModule(moduleWrittenInAmd);
> browserify -t browserifyshim -e entry.js > main.js
// package.json
{
"browser": {
"jquery": "bower_components/jquery/jquery-2.1.0.min.js"
"ember": "bower_components/ember/ember.js"
},
"browserify-shim": {
"jquery": {
"exports": "$"
},
"ember": {
"exports": "Ember"
"depends": ["jquery"]
}
}
}
//entry.js
var Ember = require('ember');
var $ = require('jquery');
CodeFest