Skip to content

Instantly share code, notes, and snippets.

@iaincarsberg
Created September 22, 2011 19:11
Show Gist options
  • Save iaincarsberg/1235722 to your computer and use it in GitHub Desktop.
Save iaincarsberg/1235722 to your computer and use it in GitHub Desktop.
RequireJS
/*global define console*/
require.config({
baseUrl: '/src',
packages: [
{
name: 'underscore',
main: 'underscore',
location: '/lib/underscore'
}
],
paths: {
cjs: '/lib/cjs/cjs',
text: '/lib/requirejs/text'
}
});
define(['require', 'cjs!underscore'], function (require, underscore) {
return function (something) {
console.log(something);
};
});
<!doctype html>
<html>
<head>
<title>Work in Progress</title>
</head>
<body>
<div id="container">
<header></header>
<div id="main" role="main" class="content"></div>
<footer></footer>
</div>
<script src="/lib/requirejs/require.js"></script>
<script>
/*global require console*/
require(['/src/app.js'], function (app) {
app('something');
});
</script>
</body>
</html>
@jrburke
Copy link

jrburke commented Sep 22, 2011

I prefer this setup:

<script data-main="/src/main.js" src="/lib/requirejs/require.js"></script>

then in main.js:
/global define console/
require.config({
baseUrl: '/src',
packages: [
{
name: 'underscore',
main: 'underscore',
location: '/lib/underscore'
}
],
paths: {
cjs: '/lib/cjs/cjs',
text: '/lib/requirejs/text'
}
});

require(['app'], function (app) {
    app('something');
});

Then leave app.js with just the define() code above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment