大佬教程收集整理的这篇文章主要介绍了javascript – 如何访问RequireJS(AMD)环境中的node.js模块?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在main.js中:
require.config ({ baseUrl: '/js',waitSeconds: 200,noderequire: require,paths: { jquery: '//cdn/jquery.min',underscore:'//cdn/underscore-min',// more plugins },shim: { // shimming stuff } }); require(['marionette','vent','config/template','app','routers/main' ],function (Marionette,vent,Template,nrtApp ) { 'use Strict'; nrtApp.module ('Public.Main',function (Main,nrtApp,BACkbone,Marionette,$,_) { nrtApp.start (); // this is where the error is: requirejs (['config'],function (config) { if (typeof config !== 'undefined') {Config.log ('ok!');} }); }); });
问题是,我想从requireJS模块加载一些npm包(例如npm install config). requireJS似乎无法找到位于与requireJS baseUrl目录不同的目录的npm node_modules目录.
以下是我的目录结构:
@H_970_4@my_project/ app/ public/ js/ main.js app.js node_modules/ config/以下是错误消息:
它试图从baseUrl目录加载模块.
如何在我的用例中从requireJS模块系统访问npm模块?
要在客户端应用程序中使用配置模块,必须先将其转换为与requireJS兼容的模块,然后将其复制到公共模块下.这篇文章explains how to automate this with package managers and build tools,并包含最终修复了我对requireJS Node的理解的引用:
以上是大佬教程为你收集整理的javascript – 如何访问RequireJS(AMD)环境中的node.js模块?全部内容,希望文章能够帮你解决javascript – 如何访问RequireJS(AMD)环境中的node.js模块?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。