2013-05-28 28 views
3

我想用當前的RequireJS項目設置使用node-bencoding包,但我一直無法配置它。如何在RequireJS中使用NodeJS包?

我按照these instructions和已經跑:

​​

然後在我的app.js文件我已經改變了它:

var requirejs = require('requirejs'); 

// Place third party dependencies in the lib folder 
// 
// Configure loading modules from the lib directory, 
// except 'app' ones, 
requirejs.config({ 
    nodeRequire: require, 
    "baseUrl": "assets/js/lib", 
    "paths": { 
     "app": "../app", 
     "jquery": "https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min", 
     "angularjs": "https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min" 
    }, 
}); 

然而,當我加載頁面出現錯誤:

Error: Module name "requirejs" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded

我不確定我應該在哪裏我的node_modules直接RY。我的目錄結構如下所示:我的所有JS文件都包含在src/assets/js中 - 有些資源/ js/app和assets/js/lib與RequireJS約定一樣。目前我已將我的node_modules目錄放在src /中。

回答

0

看起來你正試圖在瀏覽器中使用它。而您的應用程序不是服務器端JavaScript,因此Node中的RequireJS使用示例不適用。在這種情況下,您只想使用節點來優化腳本。

我最近在博客上寫了Understanding AMD & RequireJS,這可能會有用。