How to import a static url using webpack

How to import a static url using webpack:

index.js

import 'http://google.com/myscript.js'

+6
source share
2 answers

It is not clear what you are trying to do, but in general you have several options.

  • Pre-load the script or install it through NPM . This is probably the preferred way to deal with external dependencies. Once it is local, you can easily import or require like any other module.

  • If it is absolutely necessary to load dynamically , you will need a third-party module, for example https://www.npmjs.com/package/scriptjs , which can easily load third-party modules at runtime and block the rest of the script from executing until it analyzed.

  • Use the <script> and include it on your page . This only works if it's a general dependency that can be loaded before everything else (maybe for a polyfill or a library that you depend on everywhere, like jquery.)

I hope this helps!

+4
source

import - es6. Using es5 and webpack use require or better migrate JS files using AMD / UMD.

0
source

All Articles