Optional externals in amd use globals instead of an explicit dependency

There isn't any mechanism in the amdjs spec to provide optional
dependancies (although a requirejs loader plugin could do that, it's not
standard). The best approach found was knockout's optional dependancy on
jquery, for which it doesn't use require, it only uses globals.

This solution will need to be improved for use of requirejs/amd in
commonjs environments, and could be improved to allow toggling it with a flag.

Extends the solution for #339
It's making sure that optional requires aren't included in amd modules if they aren't defined, and that optional requires are included. If the test should be organized differently, or if there are tests for this elsewhere, I can remove it. I didn't see tests for optional requires for #339, so I've added some tests for that here.