peerigon / extract-loader

webpack loader to extract HTML and CSS from the bundle
The Unlicense
317 stars 74 forks source link

Webpack 5.1.3 and PublicPath auto #95

Open Magi-KS opened 3 years ago

Magi-KS commented 3 years ago

Webpack: 5.1.3 extract-loader: 5.1.0

there's this PR https://github.com/webpack/webpack/pull/11258 that was merged and released as part of Webpack 5.1.3 which changes the default publicPath option to auto.

and getPublicPath function that refers to the variable in this line

which result in require("./assets/styles/style.css") being resolved to <link rel="stylesheet" href="autoad70c8b2da42929dc855c3fd20c749b2.css"/>\n'

notice the auto.

I personally do not have any context on how this should be properly handled for extract-loader. If any veteran would provide a direction I can make the changes and submit a PR.

for people that needs a quick fix, just explicitly provide the option of publicPath as empty string like so

          {
            loader: "extract-loader",
            options: {
              publicPath: "",
            }
          },
isaacl commented 3 years ago

yeah not sure either. Possibly the following is correct, but I'm not sure if that makes extract-loader handle 'auto' correctly:

diff --git a/src/extractLoader.js b/src/extractLoader.js
index 677388d..6859ba9 100644
--- a/src/extractLoader.js
+++ b/src/extractLoader.js
@@ -216,7 +216,8 @@ function getPublicPath(options, context) {
         return context.options.output.publicPath;
     }

-    if (context._compilation && context._compilation.outputOptions && "publicPath" in context._compilation.outputOptions) {
+    if (context._compilation && context._compilation.outputOptions && "publicPath" in context._compilation.outputOptions &&
+        context._compilation.outputOptions.publicPath !== 'auto') {
         return context._compilation.outputOptions.publicPath;
     }
IgnusG commented 3 years ago

@isaacl tried it with patch-package (since it's the only package that was broken for me in webpack@5) and it worked well for now

IgnusG commented 3 years ago

Here's the favicons-webpack-plugin's commit that addresses a similar issue https://github.com/jantimon/favicons-webpack-plugin/commit/7293186bc6887352a3d31c80f4671c10734a44fb I think the solution is fairly similar to the above one