Is there any method to automatically load webpack external files?

296 views Asked by At

I organize my frontend project with commonjs like var $ = require('jquery'); and use webpack to bundle entry js files. I can use webpack's "externals" to exclude some third-party libraries like jquery, angular or others into the final bundle and i have to add some script tags to the html to load these files. Is there any method to automatically load these external files instead of adding script tags manually in the html file?

1

There are 1 answers

0
Long Nguyen On

Webpack is a module bundler not a javascript loader. It package files from local disk and don't load files from the web (except its own chunks).

Use a javascript loader, i. e. script.js

var $script = require("scriptjs");
$script("//ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js", function() {
// ...
});

For more information please refer to this issue on Webpack repo: https://github.com/webpack/webpack/issues/150