Template output fixes
- add globals JS to bottom of template so it can require modules
- fix wrong object set to [module].exports when module.exports was overwritten inside the module