I have a simple index page that uses a handful of js files, including jquery and underscore from a CDN. To learn, I want to set up requirejs to manage the scripts.
Folder structure:
exampleApp
-js
-foo.js
-main.js
-require.js
-index.html
index, note foo() is a function in foo.js:
<script data-main="js/main" src="js/requirejs-2.1.9.js"></script>
<body>
<button onclick='foo()'>Click me</button>
</body>
main.js:
requirejs.config({
baseUrl: 'js',
paths: {
jquery : '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js',
underscore : '//cdn.jsdelivr.net/underscorejs/1.5.2/underscore-min.js',
foo : 'foo'
},
shim: {
jquery: {
exports: '$'
},
underscore: {
exports: '_'
}
}
});
requirejs(['jquery', 'underscore', 'foo'], function($, _, foo){
});
In my foo.js, I use jquery using "$" and underscore using "_", so I want to maintain those symbols if possible.