joebartels / ember-cli-js-cookie

zero fanciness wrapper over the global Cookies from js-cookie library
MIT License
7 stars 4 forks source link

Use ES6 import via vendor shim #4

Open jrowlingson opened 7 years ago

jrowlingson commented 7 years ago

Ideally, it would be nice to employ a vendor-shim to avoid setting a global.

joebartels commented 7 years ago

Agree. It's sort of a fake benefit here since the addon is simply exporting the global. Perhaps this would work inside index.js

this.import('vendor/js.cookie.js', {
  using: [{ transformation: 'amd', as: 'js-cookie' }]
});
jrowlingson commented 7 years ago

I think I prefer this approach over using a vendor-shim. I took this for a quick test here but I am observing the Cookies global is still being set on window.

I will take a closer look when I get a chance.

joebartels commented 7 years ago

ah I see... it may not be possible with the regular js-cookie build. Looking at the way the code is loaded: js-cookie is looking for define.amd https://github.com/js-cookie/js-cookie/blob/master/src/js.cookie.js#L10

and ember's amd loader has this mention... https://github.com/ember-cli/loader.js/blob/master/lib/loader/loader.js#L239

jrowlingson commented 6 years ago

As of ember 2.15 app.import supports importing files from node_modules