Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add JS/CSS to HTML files for CDN resources #754

Closed
cowwoc opened this issue Feb 2, 2015 · 16 comments
Closed

Automatically add JS/CSS to HTML files for CDN resources #754

cowwoc opened this issue Feb 2, 2015 · 16 comments

Comments

@cowwoc
Copy link

cowwoc commented Feb 2, 2015

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.

@sokra
Copy link
Member

sokra commented Feb 2, 2015

This propably can be part of https://github.com/ampedandwired/html-webpack-plugin

@alexeygolev
Copy link

+1

@cowwoc
Copy link
Author

cowwoc commented Feb 5, 2015

Motivation: http://stackoverflow.com/a/558494/14731

@cowwoc
Copy link
Author

cowwoc commented Feb 5, 2015

@sokra I filed a feature request against html-webpack-plugin, but I just want to point out that it is an extremely low-volume plugin. I don't expect them to implement this (or any other new feature) anytime soon. Anyway, in the meantime I will do my best to drum up support for this feature request.

@cowwoc
Copy link
Author

cowwoc commented Feb 6, 2015

This issue is related to #536

@AlistairB
Copy link

I would also like this. There doesn't seem to be a hook to implement something like this (I'm new to webpack though so could be missing it).

Other features I want (either by configuration or a hook):

  • Use latest version from CDN (eg hit http://api.cdnjs.com/libraries?search=lodash.js and use the version you find)
  • Include fallback logic if CDN resource is not resolvable (either when building, or some in page logic that handles it).

@screendriver
Copy link

👍

@sokra
Copy link
Member

sokra commented May 17, 2015

@sokra sokra closed this as completed May 17, 2015
@cowwoc
Copy link
Author

cowwoc commented May 17, 2015

I believe the relevant issue is jantimon/html-webpack-plugin#12

@kizzlebot
Copy link

👍

1 similar comment
@sergeymorkovkin
Copy link

👍

@dongpei021
Copy link

dongpei021 commented Nov 16, 2016

I read through the thread, and the html-webpack-plugin#12, has the feature description in @cowwoc been implemented?

@cowwoc
Copy link
Author

cowwoc commented Nov 16, 2016

@dongpei021 I'm not using webpack at the moment so I can't check, but at first glance it looks like it might do it. I've asked the guys over at #536 to review it.

@bebraw
Copy link
Contributor

bebraw commented Dec 14, 2016

See html-webpack-cdn-plugin.

@shirotech
Copy link

Another solution is webpack-cdn-plugin

@geoshar
Copy link

geoshar commented Jul 9, 2018

Hey! Take a look at this one autoloader-cdn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests