windows - Simple RequireJS in node -
i exclusively use requirejs node.
i cannot seem run in same file when run "node r.js file.js":
define('a', function () { console.log("loaded a"); return {}; }); require(['a'], function(a){ }); is there way override define , require strictly requirejs' definitions.
also there way strictly r.js , not installing requirejs npm.
you can use require.js in node!
the require.js documentation includes section on installing require node.js .
first, go console (assuming have npm should) , type:
npm install requirejsafter that, you're set up. first need require require (no pun intended), in top of main js file, need like:
var requirejs = require('requirejs');then, can configure it:
requirejs.config({/*your config shims,etc goes here*/});
that's it! can use it:
requirejs(["module1","module2"],function(mod1,mod2){ //whatever here }); there more detailed instructions on this page.
a better solution bigger issue:
you can use browserify.
browserify lets share code between client , server using node.js style require() statements. shims common things process.nexttick. shims modules path, events , vm.
i have used in several production projects , works.
Comments
Post a Comment