extract-loader icon indicating copy to clipboard operation
extract-loader copied to clipboard

Webpack 5.1.3 and PublicPath auto

Open Magi-KS opened this issue 4 years ago • 3 comments

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: "",
            }
          },

Magi-KS avatar Oct 17 '20 14:10 Magi-KS

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;
     }

isaacl avatar Nov 02 '20 00:11 isaacl

@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 avatar Feb 16 '21 11:02 IgnusG

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

IgnusG avatar Feb 16 '21 11:02 IgnusG