如何在服务器端使用require.js?

我现在用Backbone.js在客户端上使用它,但是我也想用Node.js。

在requirejs主页上有方向,我发现很有用: http : //requirejs.org/docs/node.html

我也在这里设置一些例子: https : //github.com/rgarcia/node-requirejs-examples

基本的想法是,你使用它就像在客户端,但对于npm模块和内置的节点模块,你不使用相对path,而是使用模块名称。 对于所有的自定义模块,您使用相对path。

这里是在node.js上使用requireJS的文档

http://requirejs.org/docs/node.html

安装node.js

npm install requirejs 

用法示例

 var requirejs = require('requirejs'); requirejs(['foo', 'bar'], function (foo, bar) { //foo and bar are loaded according to requirejs //config, but if not found, then node's require //is used to load the module. });