Accepted answer

There is one html file that is definitely being used to serve to users with your js bundle attached. Probably you could attach the script tag into that html file


I have looked around for a solution and most of all proposals were based on externals, which is not valid in my case.

In this other post, I have posted my solution:

In other words, I finished using a separate JS file which is responsible for downloading the desired file into a local directory. Then WebPack scans this directory and bundles the downloaded files together with the application.


Use webpack's externals:

externals allows you to specify dependencies for your library that are not resolved by webpack, but become dependencies of the output. This means they are imported from the environment during runtime.


You can create a script tag in your JS as

$("body").append($("<script src=""></script>"))


var $script = require("scriptjs");
$script("//", function() {
  $('body').html('It works!')


externals is not intended to let you do this. It means "don't compile this resource into the final bundle because I will include it myself"

What you need is a script loader implementation such as script.js. I also wrote a simple app to compare different script loader implementations: link.

Related Query

More Query from same tag