我正在探索将Webpack与Backbone.js结合使用的想法。
我遵循了快速入门指南,并对Webpack的工作原理有一个大致的了解,但是我不清楚如何加载依赖库,例如jquery / boneer / underscore。
它们应该从外部加载<script>还是Webpack可以像RequireJS的shim一样处理?
按照的WebPack DOC:垫补模块,ProvidePlugin并且externals似乎与此有关(因此是bundle!装载机的地方),但我不能想出什么时候使用。
谢谢
两者都有:您可以在库中包含一个
<script>(即使用CDN中的库)或将它们包含在生成的包中。如果通过
<script>标签加载,则可以使用该externals选项允许写入require(...)模块。CDN库的示例:
捆绑包中包含库的示例:
The
ProvidePlugincan map modules to (free) variables. So you could define: "Every time I use the (free) variablexyzinside a module you (webpack) should setxyztorequire("abc")."Example without
ProvidePlugin:Example with
ProvidePlugin:Summary:
<script>tag andexternalsoptionresolveoptions to find the library)externals: Make global vars available as moduleProvidePlugin: Make modules available as free variables inside modules