-
Notifications
You must be signed in to change notification settings - Fork 20
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
AMD #54
base: master
Are you sure you want to change the base?
AMD #54
Conversation
I got a kind of environment specific building done by using the requirejs optimizer, a // main.js
require(['A'], function(){
if (shouldLoadOldIECode) require('A-oldIE');
...
}); r.js -o name=main out=main-build.js baseUrl=. excludeShallow=A-oldIE
r.js -o name=main out=main-build-oldIE.js baseUrl=. <script src=require.js></script>
<script>
if (inProductionMode) {
require.config({paths:{ main:'main-build' }});
if (shouldLoadOldIECode) require.config({paths:{ main:'main-build-oldIE' }});
}
require(['main']);
</script> Is this as insane as it feels? Is there a better way to do stuff like this? I guess ideally you'd send the client a tiny feature test script that'd figure out precisely what build you need for that environment. Then you could either pre-generate each of the possible builds ahead of time or lazily build them the first time they were requested. But until I have all that working, what's the best way to accomplish this on the small scale? |
What I also think is quite interesting is has.js with require.js optimizer: http://requirejs.org/docs/optimization.html#hasjs if (has('feature')){
...
} which turns into if (true){ ... }
// or
if (false){ ... } UglifyJS or other minfiy tools can remove dead-code branches. tbh I'm not sure how you can load or not load modules that way, but I think you could use a if (has('oldIE')){
require('A-oldIE');
} (Personally I'd love to use the I think this would work for the optimizer, for the client-side it probably will load the 'A-oldIE' anyway if the loader supports the feature that it searches for |
I would probably approach this with a loader plugin, a has loader plugin. I'm not sure if someone has made one yet, but it has been talked about in Dojo land. @rcgill may know of one used in Dojo. The basic idea though would be to do something like: // main.js and have the has plugin only load A-oldIE if the 'oldIE' test returns true. Then the has plugin during the build could try and use the same has: {} config in the build profile to know if it should include oldIE in the output. I have been meaning to make a boilerplate has plugin, where you would insert your own tests in it, if you think that would be useful for you, I can take a crack at it. |
Or, even simpler, just do: and do two different builds, one mapping A-oldIE to an empty file for the build that does not need the old IE stuff. There is shortcut for specifying an empty URL in the build profile:
You can also pass it on the command line: paths.A-oldIE=empty: |
Woah, lots of different options to explore. Very exciting. |
All of the actual files in slick...
There are still a few unsolved problems...
Node.js had its own implementation of |
I've moved the environment specific build issue to #55. That shouldn't block Slick from moving to AMD. |
My latest thinking is...
|
Slick needs to provide stable require paths. e.g.
I'm not sure I want to provide a single point of entry (i.e. |
cool to see you're targeting cpm. luv that.
I agree. The key is to provide examples that show users what to do. They'll understand it pretty quickly. :) Fwiw, curl.js 0.6 will support CJS Keep up the awesome work guys. -- John |
👍 |
This is not ready to be pulled yet, but I wanted to open up a discussion around this branch so we can discuss the implementation as it is done.
I didn't really get very far yet. I only just began learning the pragmatic details of how to use AMD. Most importantly though is how to build out a final minified build of the code.
It no longer makes sense to include all the oldIE implementations of everything right alongside the base implementation. It's far better to dynamically include that code only after a feature test proves that it is necessary. However, that complicates generating a build.
Ideally I'd like to implement environment-specific builds sooner than later. It's a very solvable problem and this is the time to make it happen. I've already gotten it kinda working, but I wanted to get some feedback before actually moving forward in that direction.
I'll post more in this thread later.