简体   繁体   中英

How to lazyload external modules using Webpack?

它能够使用externals来使用全局变量,但是可以像Code Splitting功能一样延迟加载外部js文件吗?

You should use script loader https://github.com/ded/script.js

" Like many other script loaders, $script.js allows you to load script resources on-demand from any URL and not block other resources from loading (like CSS and images)."

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

I've written a loader that allows you to expose modules from one webpack build to others via a global defined namespace, this lets you define which modules you want to share between the webpack builds and allows you to share common modules while maintaining the bundles intact.

https://github.com/MrFrankel/share-loader

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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