Reputation: 6396
How can I import a static url using webpack:
index.js
import 'http://google.com/myscript.js'
Upvotes: 22
Views: 18256
Reputation: 586
This webpack issue says you can use this comment to allow the import to just work. Though this is only dynamic import not static.
import(/* webpackIgnore: true */ "https://example.com");
First seen here https://stackoverflow.com/a/69951351/4619267
Upvotes: 4
Reputation: 1152
import
is es6. With es5 and webpack, use require
, or better wrap your JS files with AMD/UMD.
Upvotes: -3
Reputation: 17014
It's really unclear what you're trying to do, but in general you have a few options.
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.
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.
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!
Upvotes: 10