Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import static url using webpack

How can I import a static url using webpack:

index.js

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

like image 367
eguneys Avatar asked Jul 15 '15 08:07

eguneys


1 Answers

It's really unclear what you're trying to do, but in general you have a few options.

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

  2. If it absolutely must be loaded dynamically you will need a 3rd party module such as https://www.npmjs.com/package/scriptjs which can easily download 3rd party modules at runtime and block the execution of the rest of the script until it has been parsed.

  3. Use a <script> tag 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 you depend on everywhere like jquery.)

I hope that helps!

like image 79
Jamund Ferguson Avatar answered Oct 05 '22 10:10

Jamund Ferguson