Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

loader.option.publicPath do not work ? #323

Closed
huyansheng3 opened this issue Jun 29, 2021 · 7 comments
Closed

loader.option.publicPath do not work ? #323

huyansheng3 opened this issue Jun 29, 2021 · 7 comments

Comments

@huyansheng3
Copy link

huyansheng3 commented Jun 29, 2021

  • Operating System:
  • Node Version:
  • NPM Version:
  • webpack Version:
  • worker-loader Version:latest

when i run the test case, *.chunk.js use the loader.option.publicPath, but the *.worker.js do not use the loader.option.publicPath

it('should work and respect the "output.publicPath" option default value', async () => {
    const nanoid = customAlphabet("1234567890abcdef", 10);
    const compiler = getCompiler(
      "./chunks/entry.js",
      {
        worker: "SharedWorker",
        filename: "[name].[contenthash].worker.js",
        chunkFilename: "[id].[contenthash].worker.js",
        publicPath: "/public-path-static123/",
      },
      {
        output: {
          path: path.resolve(__dirname, "./outputs", `test_${nanoid()}`),
          filename: "[name].bundle.js",
          chunkFilename: "[name].chunk.js",
          publicPath: "/public-path-static456/",
        },
      }
    );
    const stats = await compile(compiler);
    const result = await getResultFromBrowser(stats);

    expect(getModuleSource("./chunks/worker.js", stats)).toMatchSnapshot(
      "module"
    );
    expect(result).toMatchSnapshot("result");
    expect(getWarnings(stats)).toMatchSnapshot("warnings");
    expect(getErrors(stats)).toMatchSnapshot("errors");
  });

image

image

http://localhost:5000/public-path-static456/worker.9ce1180cb43e7000b1a2.worker.js should be /public-path-static123/worker.9ce1180cb43e7000b1a2.worker.js ?

@huyansheng3
Copy link
Author

huyansheng3 commented Jun 29, 2021

rewritePublicPath.js

 __webpack_public_path__ = '/';

import './rewritePublicPath.js'

// import UpgradeSharedWorker from './upgrade-notify.sharedworker.js';

#281 this can fix the problem, maybe is not a good solution.

@alexander-akait
Copy link
Member

What is webpack version?

@huyansheng3
Copy link
Author

huyansheng3 commented Jun 29, 2021

wepack 4.x or 5.x has the same problem .

I just modify the project test case; then see the /outputs content @alexander-akait

@alexander-akait
Copy link
Member

you don't need this loader for webpack v5

@alexander-akait
Copy link
Member

We describe it in our readme https://github.com/webpack-contrib/worker-loader#readme

@huyansheng3
Copy link
Author

oader.option.public�Path only add to the webpack output.publicPath, can only set the worker.js full public path

@mmazzarolo
Copy link

@alexander-akait just a note: AFAIK Webpack 5 implementation of the loading mechanism doesn't support setting publicPath specific only to web-workers. It will always use whatever is set in output.publicPath (which might not be the same path you need for the worker).

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

No branches or pull requests

3 participants