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 namednode_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 likedefine(['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
1 Answer
Reset to default 6In 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($){
....
});