简体   繁体   English

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

[英]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 在requirejs主页上有一些方向我发现非常有用: http//requirejs.org/docs/node.html

I also set up some examples here: https://github.com/rgarcia/node-requirejs-examples 我还在这里设置了一些例子: 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. 基本思想是您在客户端使用它,但对于npm模块和内置节点模块,您不使用相对路径,而是使用模块名称。 For all of your custom modules you use the relative path. 对于所有自定义模块,请使用相对路径。

Here is the doc for usage of requireJS on node.js 这是在node.js上使用requireJS的文档

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

Install the node.js 安装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.
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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