I'm using RequireJS to load some modules.
I'm serving static assets using a mirror CDN. The problem is that modules are loaded relatively to the website domain and not to the data-main file, so that modules are loaded this way:
my-website.com/
↳ cdn.com/assets/js/require-main.min.js
↳ my-website.com/assets/js/helper-module.js
↳ my-website.com/assets/js/utility-module.js
Is there a way to load modules relatively to the data-main file, in order to serve modules using the CDN?
my-website.com/
↳ cdn.com/assets/js/require-main.min.js
↳ cdn.com/assets/js/helper-module.js
↳ cdn.com/assets/js/utility-module.js
I can't hard-code the CDN domain anywhere since it is not always the same.
This is a sample of require-main.js
requirejs.config({
baseUrl: "../js/",
waitSeconds: 15,
paths: {
helper: "helper-module",
...
}
});
and this is the rjs.optimize
function I use to minify all the assets and combine some modules
rjs.optimize({
appDir: './assets/js/',
baseUrl: ".",
mainConfigFile: './assets/js/require-main.js',
dir: './public/assets/js/',
preserveLicenseComments: true,
optimize: 'uglify2',
findNestedDependencies: true,
logLevel: 0,
uglify2: {
mangle: false
},
modules: [
{
name: 'require-main'
...
}
],
removeCombined: true,
writeBuildTxt: false
});