Javascript 如何将NodeJS包与RequireJS一起使用?
我想在当前的RequireJS项目设置中使用Javascript 如何将NodeJS包与RequireJS一起使用?,javascript,node.js,requirejs,Javascript,Node.js,Requirejs,我想在当前的RequireJS项目设置中使用节点bencoding包,但我无法对其进行配置 我跟随并跑过: npm安装要求 npm安装节点bencoding 然后在我的app.js文件中,我更改了它: var requirejs = require('requirejs'); // Place third party dependencies in the lib folder // // Configure loading modules from the lib directory, //
节点bencoding
包,但我无法对其进行配置
我跟随并跑过:
npm安装要求
npm安装节点bencoding
然后在我的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"
},
});
但是,当我加载页面时,会出现以下错误:
错误:尚未为上下文加载模块名“requirejs”:。使用require([])
我不确定我的
node\u模块应该放在哪里。我的目录结构如下:我的所有JS文件都包含在src/assets/JS中——有assets/JS/app和assets/JS/lib,这是RequireJS约定。目前,我已将我的node_modules目录放在src/中,看起来您正试图在浏览器中使用它。而且您的应用程序不是服务器端JavaScript,所以节点中的RequireJS用法示例不适用。在这种情况下,您希望仅使用node来优化脚本
我最近写了一篇博客,它可能会有用