Skip to content

Instantly share code, notes, and snippets.

@Siedrix
Created December 27, 2011 06:10
Show Gist options
  • Save Siedrix/1522849 to your computer and use it in GitHub Desktop.
Save Siedrix/1522849 to your computer and use it in GitHub Desktop.
RequireJs on Node
var requirejs = require('requirejs');
requirejs.config({
baseUrl: 'scripts',
nodeRequire: require
});
requirejs(['bar'],
function ( bar ) {
console.log('bar: ', bar);
});
define(['dep/foo'], function (fs,foo) {
console.log('foo', foo.isFoo ? true : false)
return {
isDepOfFoo : foo.isFoo ? true : false,
isBar : true
};
});
define(function (fs) {
return {
isFoo : true
};
});
<!DOCTYPE>
<html>
<head>
<title>RequireJs</title>
<script type="text/javascript" src="scripts/require.js"></script>
</head>
<body>
<script type="text/javascript">
requirejs.config({
baseUrl: 'scripts',
urlArgs: "bust=" + (new Date()).getTime()
});
requirejs(['bar'],
function ( bar ) {
console.log('bar: ', bar);
});
</script>
</body>
</html>
@Siedrix
Copy link
Author

Siedrix commented Dec 27, 2011

bar.js debe de ir en un folder llamado scripts
foo.js debe de ir en un folder llamado dep, dentro de scripts

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