-
Notifications
You must be signed in to change notification settings - Fork 670
Calling Optimizer Programmatically via Rhino #382
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
Comments
I apologize if I posted this prematurely. I may just not be loading it up correctly. Using this: require(['requirejs'], function(requirejs) {
// call requirejs.optimize with config
} I now just get the error that |
Correct, right now optimize() is not exposed to rhino. If a rhino branch was added after this: and createRjsApi(); was called in there (not sure what to set for baseUrl), then I would probably work. However, I have not done the work to try it and test it out. If you want to give it a shot and see how it goes, I'm all for that. After doing that change in x.js, then run |
Great, thanks for that. I'll give all that a spin and see if I can't get things working. |
Yep, I was able to add that section and then, as a stand-in, use "." as the baseUrl and it worked! diff --git a/build/jslib/x.js b/build/jslib/x.js
index 83b5253..27186fb 100644
--- a/build/jslib/x.js
+++ b/build/jslib/x.js
@@ -266,6 +266,10 @@ var requirejs, require, define;
setBaseUrl(location.href);
createRjsApi();
return;
+ } else if (env === 'rhino') {
+ setBaseUrl('.');
+ createRjsApi();
+ return;
}
if (commandOption === 'o') { I'm certain this is not comprehensive enough, given the checking you do in the node section of this conditional, but at least I can verify that it works. I still encountered some exceptions, but I think that lies in my own code. I'll let you know if I have any more info. |
Maybe for the rhino case, it should be |
That makes the most sense to me.
|
The other trick with that piece of code -- it knows to bail early instead of processing command line args because in node, it figures out it is called as a module, and in the browser, it can only be used a library. However, for rhino, the primary use case is command line arg processing. Can you describe how you loaded the r.js file in rhino, and what thing I could detect to know if it was OK to do the createRjsApi() work and return early because r.js is being used like a library and not a command line tool? |
I'd have to do a little research to see if there were anything that could be checked programmatically to differentiate between running r.js on the command-line vs. as a library. At the very least, I'm sure we could use some Java reflection facilities to see how the current Rhino environment has been started or is running from inside r.js itself. I'll report back if/when I figure something out. As for my own use of r.js programmatically, I do the following:
So from a Rhino perspective, I start up Rhino, I setup a few definitions, then I evaluate all of r.js by passing in a |
Alright, found out. When you run Rhino from the command-line, you should have access to an |
The If we figure out something later that works better that would be great, but for now it is usable. Try the master snapshot to confirm that it works for you, but I also hope to do a 2.1.5 release within the next day. |
I see at this line, that the function for
optimize
is added to therequirejs
object at this point in the code:https://github.com/jrburke/r.js/blob/3401eeee35d4fe750139efc2c128ac325abf9ccb/dist/r.js#L23891
This doesn't seem to account for Rhino, and when I inspect the
requirejs
object via Rhino, I see that'optimize'
is not one of the available fields. Is this intentional? Is there a way other thanrequirejs.optimize
that one calls the optimizer programmatically via Rhino?The text was updated successfully, but these errors were encountered: