-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if a module exists before requiring it #984
Comments
It's unclear to me how I could address my use case with Let me clarify my use case... I do R&D for a JavaScript library called LuciadRIA. The "pro" version of LuciadRIA has an optional component called "military symbology" that can be included by just unzipping the content of a zip file into the LuciadRIA root directory. This adds both additional library files and additional samples. Two of our samples use a custom AMD plugin named On Friday I worked out an architecture that allows the code of this plugin (as well as another custom plugin) to be used directly in the browser and to have it optimized by r.js. However, that architecture has quite a few flaws, including causing our Jenkins build to break. I raised this as a separate issue (#983). Anyway, I'm using Ajax to detect the presence of a module when running my modules unbundled and Because I'm unable to do this check in r.js, I currently have to assume either that "military symbology" is present or that it is not present at build time. If I assume the former, the build will break when it is not present. If I assume the latter, modules that should be bundled are not. |
For build situations, instead of using an ajax call, the plugin can detect if it is in a build, and either just do nothing, by calling the load function passed to it, or it could use node APIs, like The text plugin as an example of checking the and it also will use node APIs, like |
I'm working on a plugin where I need to check if module
namespace/A
is available on the server. If it is available, I want to loadnamespace/A
. If it is not available, I want to loadnamespace/B
as a fallback.Now, depending on whether my modules are bundled, I could use an Ajax call or
require.specified()
to check for availability when running my code in a browser. It's far from a perfect solution, but it kinda sorta works (See requirejs/requirejs#1737).But what should I do when running this code in r.js?
How can I figure out whether a module exists before I try requiring it?
Is there a way I can just ignore non-existing modules in r.js without breaking the build?
The text was updated successfully, but these errors were encountered: