2

Instead of adding <script src="https://checkout.stripe.com/checkout.js"></script> in the Index.html is it possible to add somehow URL for this JS-file in the package.json file (it is simple JS-file, not NPM package; and it is just URL for this JS-file, not GitHub URL) to NPM download and install it? The reason for it - there is a Webpack config which make some processing of all used JS-files. May be it is better to include all external JS-files (not NPM packages) into this Webpack processing

osya
  • 91
  • 2
  • 10

1 Answers1

3

If you are already using Webpack you may consider using something like little-loader.

npm i little-loader --save

And then in your code

var load = require("little-loader");

load("https://checkout.stripe.com/checkout.js", function (err) {
  // ... your code ...
});

You can get some more inspiration from other answers as well.

In the Webpack issues I see the maintainer suggesting this approach:

var $script = require("scriptjs");
$script("https://checkout.stripe.com/checkout.js", function() {
  //.... your code ...
});

But that package looks a bit unmaintained.

At the end of the day, an option to consider is to just leave it in the HTML as well, it's not necessarily a bad thing.

Community
  • 1
  • 1
Aurelio
  • 24,702
  • 9
  • 60
  • 63
  • I got it. You are talking about how to download external JS-file from JS-code. But how to make Webpack to get external JS-file and add it to the vendor.js? – osya Mar 23 '17 at 21:15
  • The way I am aware (and it does **not** mean there aren't others...) is to make Webpack look for your scripts in `node_modules` or specify a path like `./../../../../my-script.js`. Sometimes it's just easier to publish your script on npm or fork an unpublished script from a Github repo and publish it yourself. If you are using Stripe though chances are there is a good reason why they want you to use the online version (see security updates). I wouldn't look for other ways to include that 3rd party script, I would just call it over the wire with one of the methods above. – Aurelio Mar 23 '17 at 21:23