File structure
├── app.js
├── index.html
├── lib
│ ├── modules
│ │ └── template.js
│ ├── require.js
│ └── underscore.js
index.html
<html>
<head>
<script src="lib/require.js" data-main="app"></script>
</head>
<body>
<h1> RequireJS Sample Page </h1>
</body>
</html>app.js
require.config({
paths: {
"jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min", //no js extension
"underscore": "lib/underscore",
}
});
require(['lib/modules/template'], function(template) {
template.showName("Jack");
});template.js
define(['underscore', 'jquery'], function() {
var showName = function(n) {
var temp = _.template("Hello <%= name %>");
$("body").html(temp({name: n}));
};
return {
showName: showName
};
});