最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - RequireJS Config mapping whole directories - Stack Overflow

programmeradmin2浏览0评论

Is it possible to map a whole directory the node_modules directory for example to src/lib/ in the require config?

Sample Project:

project/  
project/node_modules  
project/src/  
project/src/lib/

Is it possible to map a whole directory the node_modules directory for example to src/lib/ in the require config?

Sample Project:

project/  
project/node_modules  
project/src/  
project/src/lib/
Share Improve this question edited Dec 13, 2013 at 17:37 m59 43.8k14 gold badges121 silver badges139 bronze badges asked Dec 13, 2013 at 16:01 dkroydkroy 2,0202 gold badges21 silver badges41 bronze badges 5
  • By map do you mean configure the path? – Shuhel Ahmed Commented Dec 13, 2013 at 17:42
  • @Shuhel With RequireJS terminology I want the the functional equivalent of using config.path on all of the files in the directories specified while be implicitly defined in the config file using their parent directories instead of doing it for each and every one. For example I want to call require['../node_node_module/jquery'] as require['lib/jquery']. – dkroy Commented Dec 13, 2013 at 18:49
  • Still not sure what you want but in RequireJS you actually can configure paths that points to a folder. And, you can name your path whatever you want. For example, if you have a folder named node_modules and you have some libs there including jquery, you can configure a path like, require.config({paths: {'lib' : '/path_to_node_module_folder' }}); and later in your module you can require jquery like define(['lib/jquery', function($){ .... }]). Does it answer your question? – Shuhel Ahmed Commented Dec 14, 2013 at 9:19
  • Make that an answer and I will accept it. For some reason, it didn't click with me to configure the path of directories and not just individual JavaScript assets. – dkroy Commented Dec 15, 2013 at 7:28
  • I did make it an answer. – Shuhel Ahmed Commented Dec 15, 2013 at 13:57
Add a ment  | 

1 Answer 1

Reset to default 6

In RequireJS you actually can configure paths that points to a folder. And, you can name your path whatever you want. For example, if you have a folder named node_modules and you have some libs in there including jquery, you can configure a path like

require.config({
  paths: {
    'lib' : '/path_to_node_module_folder' 
  }
}); 

and later in your module you can require jquery like

define(['lib/jquery'], function($){ 
     .... 
});
发布评论

评论列表(0)

  1. 暂无评论