-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
Currently, when loading resources from CDNs, you need to manually add <script>
and <link>
tags to the HTML file, exports
to the Webpack configuration and require()
to the code that uses it. This is error prone for transitive dependencies (users may forget to add a <script>
or <link>
tag). Example:
index.html
depends on index.js
which depends on chunk.js
which depends on jquery.js
. The author of index.js
may forget to add <script>
and <link>
tags for chunk.js
's dependencies. This quickly gets out of hand as soon as dependencies have their own dependencies.
The fact that chunk.js
invokes require('./jquery.js')
should cause a <script type='text/javascript' src='cdn/jquery.js'>
to get added to index.html
on their behalf. Similarly, the fact that chunk.js
invokes require('./jquery.css')
should cause a <link rel='stylesheet' type='text/css' href='cdn/jquery.css'/>
to get added on their behalf.
In an ideal world I'd tell webpack (at build-time) what scripts to load asynchronously, but then have require('foo')
resolve synchronously at runtime, and have the library loaded without exporting globals. I'm not fixated on any particular implementation details.