javascript - Related paths for dependencies in RequireJS define -
in requirejs module, want load related files dependencies. files in same folder module define(). module , related files maybe move location.
how can set define's dependencies related paths?
movablemodule.js
now:
define('movablemodule', [ "changable/path/to/my/modules/relatedfile1", "changable/path/to/my/modules/relatedfile2" ], function(){ console.log("movablemodule loaded"); });
movablemodule.js
want this:
define('movablemodule', [ "./relatedfile1", "./relatedfile2" ], function(){ console.log("movablemodule loaded relatively!"); });
as know calling require.config
, using baseurl
change routes in modules, yes? , if no, don't know how use in case.
you should configure requirejs define different paths.
request module, name :
require.config({ baseurl: "/", paths: { "relatedfile1": "changable/path/to/my/modules/relatedfile1" } });
then you'll able :
define('movablemodule', [ "relatedfile1" ], function(){ console.log("movablemodule loaded"); });
also, mentionned in comments, can define partial path, , use later incoming modules :
require.config({ baseurl: "/", paths: { "modulepath": "changable/path/to/my/modules/" } });
and require modules :
define('movablemodule', [ "modulepath/module1", "modulepath/module2" ], function(){ console.log("movablemodule loaded"); });
Comments
Post a Comment