Reputation: 2083
I have a file structure which looks like this:
/js
/vendor/
/spec
|-main.js
spec/min.js
is my entry point and from it I load modules in /js,
/vendor
, /spec
Actually to make the things working properly I need to put baseUrl: '../'
.
Since the directory js, vendor and spec have many subdirectories, is quite boring to handle them, also because If I change something in file structure I need to change a lot of strings.
My question is:
is possible using requirejs to set different paths
or a variable to which refer?
Obviously, without defining any global variable.
Example:
require.config({
baseUrl: '../',
paths: {
userView: 'js/users/views/userView' // how it works
userView: baseDir + '/jquery' // possible solution where baseDir = js/users/views/
}
});
Upvotes: 1
Views: 2433
Reputation: 8044
To avoid creating global variables you could just wrap it in a self-invoking function:
(function() {
var baseDir = 'something/';
require.config({
baseUrl: '../',
paths: {
userView: 'js/users/views/userView' // how it works
userView: baseDir + '/jquery' // possible solution where baseDir = js/users/views/
}
});
})();
Upvotes: 2