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
clarify doc on load()'s parentRequire parameter #1445
Comments
Seems reasonable to tweak the docs. End users of plugins are thinking more in terms of the |
The thing that bothers me about the current behavior is that the same plugin will load a different file based on the module that called the plugin. This means in some cases the require(["./foo"]) will pull one module to load from one location, and another plugin call will cause require(["./foo"]) to load a different one. If a plugin is going to load a module, shouldn't it always know what module it is going to load, and not base it on the module context that called it? |
Mentioned in doc that the relative IDs are relative to the module referring to the ID, updated the site. If the loader plugin wants a define(function(require) {
return {
load: function(id, parentRequire, onload, config) {
// use require() for plugin-relative IDs
}
};
}); |
Ah, that outer require that is now scoped to the inner load function makes more sense now! Thanks! |
The
parentRequire
parameter passed to a plugin'sload()
method (and alsowriteFile()
method?) seems to run in the context of the code that called the plugin, rather than in the plugin's context. I presume that's intentional. However, the documentation simply definesparentRequire
as:So, you should probably update the doc.
You can confirm the current behavior by sticking a relative MID in your plugin. For example:
This tries to load
foo
from the directory of the code that called the plugin, rather from the directory where the plugin lives.I also tested that a
map
configuration on the code that calls the plugin affects how thatparentRequire()
method works.The text was updated successfully, but these errors were encountered: