Hiding globals introduced by bower packages


#1

How do we get rid of globals introduced by a bower package?

bower install base64-js --save

I’m just getting the hang of how this works and If I understand correctly, the globals get introduced as soon as we add an import to ember-cli-build.js such as:

app.import('bower_components/bas64-js/lib/b64.js') 

I tried creating a vendor shim for the above package so that package variables can be ES6 imported rather than accessing them via globals. The shim works but the package’s globals still hang around on window.

To create a shim, we do need to add an app.import causing the package’s top level variables to get introduced as globals.

One of the globals in the package is a function called init() - a common name and any legitimate undefined init function will no longer be an undefined error due to this global init.

Is there any way to avoid introducing the globals? I would like to avoid modifying the original bower package as a solution.


#2

delete window.whatever ?


#3

thanks for your reply but I need a way to avoid the variables from becoming globals rather than deleting them.