Skip to content

Nested workers not resolved correctly output.publicPath is relative #89

Open
@xenobytezero

Description

@xenobytezero

I assume this is a side-effect of Angular's use of this plugin, but I can see how this could affect other setups.

Reproduction Steps

1/ Clone test repo - https://github.com/xenobytezero/worker-plugin-nested-bug.git
2/ npm install
3/ npm run build
4/ npm run testServer

This will start up a HTTP server running on localhost:5000 and show the following

screenshot-localhost_5000-2020 08 26-17_57_38

5/ Rename the serve_bug.json to serve.json and rename the existing one to something else
6/ Modify the webpack.config.js to change the output.publicPath value to be dist/

This replicates the end result of our current server setup using Angular, where the HTTP server serves the root folder, writes the publicPath to the dist/ folder, but resolves the root URL to serve dist/index.html.

7/ npm run build
8/ npm run testServer

This will start the HTTP server again and show the following

screenshot-localhost_5000-2020 08 26-18_05_03

and if you open DevTools you will see the following

Annotation 2020-08-26 180632

Investigation

I believe the problem lies in the loader.js line 87

return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} __webpack_public_path__ + ${JSON.stringify(entry)}`);

The plugin writes the module.exports to prefix the path with the Webpack public path (__webpack_public_path__), which in this case adds a second /dist onto the path and produces a 404.

Also a much less important side effect, nested Workers get a second .worker on their built filename. No real effects, just looks weird.

Proposal

I've been trying to come up with a solution for this, and I think my lack of Webpack experience is getting in the road. Essentially the path used in the line above should be relative to the source file rather than just the public path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions