Description
Normally, when you have assets in CSS that reference absolute or relative paths (e.g., content: url(/images/logo.svg)
), the asset is resolved from the same host as the CSS file.
When using webpack, if you set output.publicPath
to a relative path, CSS that gets injected into the page with JavaScript uses the host for the current document to resolve these paths.
If you host your static assets on a CDN, you can add a prefix to output.publicPath
so that the assets resolve from the CDN's host. This transformation is applied during build-time. However, if you use __webpack_public_path__
to provide a public path to a CDN during run-time, the relative paths in CSS will unexpectedly resolve from the host of the current document.
Is this something that can be fixed?
I've looked at using ExtractTextPlugin to workaround this issue (since a CSS file on the CDN will cause the paths to resolve to the CDN), but I'd still prefer to have the CSS injected into the page through JavaScript.
Also, it seems like not using __webpack_public_path__
would be the easiest solution. However, there are some technical reasons why we want to provide a CDN at run-time rather than at build-time (load balancing issues, being able to change CDN configuration without re-building, etc).
Any suggestions on what else can be done?