jeudi 5 septembre 2019

How can I ember a 3rd party js lib via a script tag in Ember?

I'm trying to integrate Plaid with an Ember and am following the instructions on their site. It should be simple, the instructions say to just add

<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js" />

and it'll give you a Plaid class that can be used to interface with Plaid.

That works fine, but ideally I'd like to vendor this script and import it in a service where I can do my work on it. This does not work out of the box. Unfortunately, this script relies on being embedded with a script tag. If you unminify the thing, there's a line where it very explicitly tries to find the script tag that embedded it, and it throws an error if it can't find it.

From the unminified code:

findScriptTag: function() {
  for (var t = document.getElementsByTagName("script"), n = 0, e = t.length; n < e; n += 1)
    if (/link-initialize(\..*?)?\.js$/.test(t[n].src)) return t[n];
  throw new Error("Failed to find script")

My question is, can I configure ember to load certain vendored scripts separately from everything else, in its own script tag? I'd also need to control the name of the file, since the above expects the name to be link-initialize.js.

My current workaround is to just add the script tag to index.html, but I'd really like to be able to say import Plaid from 'plaid';, or something close to that... Unit testing is impossible without this.




Aucun commentaire:

Enregistrer un commentaire