简体   繁体   English

有没有什么方法可以自动加载 webpack 外部文件?

[英]Is there any method to automatically load webpack external files?

I organize my frontend project with commonjs like var $ = require('jquery');我使用 commonjs 组织我的前端项目,例如var $ = require('jquery'); and use webpack to bundle entry js files.并使用 webpack 捆绑入口 js 文件。 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.我可以使用 webpack 的“externals”将一些第三方库(如 jquery、angular 或其他库)排除在最终包中,并且我必须向 html 添加一些脚本标签以加载这些文件。 Is there any method to automatically load these external files instead of adding script tags manually in the html file?有什么方法可以自动加载这些外部文件,而不是在 html 文件中手动添加脚本标签?

Webpack is a module bundler not a javascript loader.的WebPack是一个模块捆绑不是一个JavaScript加载器。 It package files from local disk and don't load files from the web (except its own chunks).它从本地磁盘打包文件并且不从网络加载文件(除了它自己的块)。

Use a javascript loader, ie script.js使用 javascript 加载器,即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有关更多信息,请参阅 Webpack 存储库上的此问题: https : //github.com/webpack/webpack/issues/150

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM