1

I am trying to use https://www.npmjs.com/package/braintree-web with Aurelia (using the aurelia-cli and RequireJS). I am stuck trying to get all the many dependencies to resolve.

To use 3rd party library in Aurelia the library must be defined in the aurelia.json file.

If I add "braintree-web" in that file then aurelia complains that "braintree-web" it requires the modules "american-express", "apple-pay" etc etc.

If I manually create the "american-express", "apple-pay" dependencies then each one also refers to "braintree-web/lib", and a bunch of other sub-directory dependencies.

In short I can't get the "braintree-web" module to load because I have to manually build all sub-dependencies and its too complex to get working.

As I state above, I am using requireJS, should these dependencies all resolve correctly?

Any ideas as to how I can get this working?

Thanks

user1980833
  • 211
  • 1
  • 2
  • 8

1 Answers1

0

If all dependencies is what you need, then with requirejs + aurelia-cli you'll have to declare all dependencies. There is an experimental version of the cli being developed which you can find here, where you won't have to declare any dependencies in aurelia.json anymore.

With webpack you also don't need to declare any dependencies by the way.

Do you really need everything though? The docs mention for example you could import just the client. Still looks like a whole heap of dependencies, but at least a lot less than importing the main index.js.

You could also just include their pre-bundled client which I believe is https://js.braintreegateway.com/web/3.32.1/js/client.min.js

On a side note, the person developing aforementioned experimental CLI is actually looking for people to test it with non-trivial apps. Me and several others have tried it with great results, so I can recommend you try it. If you could report back in the PR that would be really awesome.

Fred Kleuver
  • 7,797
  • 2
  • 27
  • 38
  • Thanks for this. How would I go about including the pre-bundled client directly in my code? I need to be able to import the code in my view model so I can call the client. i.e. I need to say "import * as client from X" – user1980833 Apr 25 '18 at 17:03
  • Probably easiest to download the pre-bundled file, and save it under `scripts/braintree-web.3.32.1-client.min.js` or something among those lines. Then just add it to the `prepend` section of your bundles, right before `require.js`. It'll be globally available via the `braintree.` namespace. Installing `@types/braintree-web` as a dev dependency is probably a good idea if you're using typescript. – Fred Kleuver Apr 25 '18 at 19:38
  • Thanks Fred, I'll have a look at that PR too. – user1980833 Apr 26 '18 at 07:25
  • Setup is the same, just checkout the right tag: `git clone https://github.com/huochunpeng/cli aurelia-cli` `git checkout tags/at12` `cd aurelia-cli` `npm install` `npm link` `npm install gulp@^4.0.0 typescript babel-register babel-polyfill` and you're done. Then in project directory `npm link aurelia-cli` – Fred Kleuver Apr 26 '18 at 09:06