My goal is to have a dependency, foo, to load from a CDN with a local fallback and to use RequireJS optimizer (r.js) to bundle and minify everything else.
require(['foo'], function (foo) { /*...*/ })
calls should work without errbacks - at least not everywhere that depends on foo, I'm cool with defining one errback in a shared location if it was possible but the global onError
seems like it cannot be used in this manner.
The config that works without r.js:
require.config({
// ...
paths: {
'foo': [
'//path-to-cdn',
'lib/local-path' // The fallback path
]
}
]);
The optimize call in gulpfile:
requirejs.optimize(
{
mainConfigFile: 'path-to-config',
name: 'path-to-main',
out: 'path-to-dist'
}
The output after I changed the foo's path to an array (instead of a single string):
Error: paths fallback not supported in optimizer.
I've tried supplying paths as an override to the optimize call as recommended without success:
requirejs.optimize(
{
// ...
paths: {
'foo': [
'https://path-to-cdn',
'lib/local-path' // The fallback path
]
}
}
This sounds like a basic requirement to me, can't I specify a fallback path for a module using RequireJS and its optimizer?