简体   繁体   中英

How do I use require.js on the serverside?

我现在使用Backbone.js在客户端上使用它,但我也想将它与node.js一起使用。

There are directions on the requirejs homepage that I found pretty useful: http://requirejs.org/docs/node.html

I also set up some examples here: https://github.com/rgarcia/node-requirejs-examples

The basic idea is that you use it just like on the client side, but for npm modules and built-in node modules, you don't use the relative path, but rather the module name. For all of your custom modules you use the relative path.

Here is the doc for usage of requireJS on node.js

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

Install the node.js

npm install requirejs

Usage example

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.
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM