Add support for excluding UMD modules

There are probably many ways of doing this, but this solution tries to add as little overhead to the build result as possible.

I kept the old preamble for builds that does not link any externals and created a modified version for builds that does link externals. This way we don't add any dead code.