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
Sort required externals to the front of the argument list. Equivalent of (es6 + underscore) `var [optionalExternals, requiredExternals] = _.partition(externals, function(m) { return m.external; });`