-
Notifications
You must be signed in to change notification settings - Fork 37
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
Expose a public API through a global without path aliases? #26
Comments
To use a "global" instead of a local variable, you just need to set the Also, I am about to add a new option, called prefixTransform Example amdclean.clean({
'code': 'var example = require("util/anotherModule");',
'prefixTransform': function(moduleName) {
return moduleName.substring(moduleName.lastIndexOf('_') + 1, moduleName.length);
}
}); This would result in the following code: |
You can now use the |
Hey, elegant solution. Thank you! |
@vonWolfehaus Glad you like it! Does this work for you? Do you need anything else? |
It does work, much appreciated. At least I think so, as what I'm seeing might be another issue entirely. I have an inline require: |
The file in question is this one, forgot to mention. |
I'm creating a little game framework, and with these sorts of things developers expect a global namespace that holds an API they can access. Take a look at Phaser as an example: Richard has
var Phaser = {}
, so it's attached to the window, then devs can instantiate modules within that namespace, like this:var player = new Phaser.Sprite()
.I'm using requirejs for development, but I'd like to use amdclean to strip it away and simply leave a global object containing an exposed API similar to Phaser's. AMDclean gets so close, as you can see in this snippet.
The problem is that it takes the relative path of the module, like
util/Thing
and turns it intoutil_Thing
. Honestly, there's nothing else out there that even gets this close, but it'd be a lot nicer if there was an option that stripped out the path automatically and placed it on the declared global object, so it'd becomemyGlobal.Thing
instead ofmyGlobal.util_Thing
.Also notice that the global isn't prepended to
display_Whatever
in that linked snippet, so that's also an issue, I think?I have too many modules to keep up a list of any kind, so making path aliases as suggested in the ReadMe is not an option for me. I understand there's danger of collisions, and while that wouldn't happen in my case, this could be a place for more control, such that a module path can be aliased away if things get too crazy (eg
my/really/deep/Module
to be attached asmyGlobal.deep.Module
. It'd be cool to map any path to any alias on the global! And I might be wrong, but I think r.js only takes module names, not paths, and aliases them?Any pointers would be greatly appreciated if I'm actually doing something wrong too! Thanks for this excellent build tool!
The text was updated successfully, but these errors were encountered: