Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[path] replacer token passed to workerize-loader has stopped working in Webpack 5 #130

Open
rjgotten opened this issue Sep 12, 2022 · 0 comments

Comments

@rjgotten
Copy link

rjgotten commented Sep 12, 2022

Used to be the case with Webpack 4 that we could pass [path][name].[contenthash] as the name template for workerize-loader to use; and we'd get workers output into a folder structure mirroring their original source location.

This was nice for debugging purposes to easily identify workers, because the entry point file for esp. larger workers is usually some kind of index.js file. [path] means you don't need to inspect every separate worker named index.[hash].worker.js - and it prevented name collisions when you would generate names in development builds without hash fingerprints in them.

As of Webpack 5, that functionality appears to be broken. It resolves [name] and [contenthash] just fine, but doesn't know how to deal with [path].

I'm using a plugin to dynamically inject options into loaders to configure bare loader URLs such as

import worker from "workerize-loader!./path-to/worker"

centrally, and luckily I was able to extend the logic there to use the current compilation context and module context to compute a relative path, but yeah... this is not very ergonomic, easily understood or maintainable:

new InjectOptionsPlugin({
  loaders : {
    "workerize-loader" : ( module, compilation ) => {
      const context = path
        .relative( compilation.options.context, module.context );
        .replace( /\\/g, "/" );
        
      return {
        name : dev ? `${context}[name]` : "${context}[name].[contenthash]`
      };
    }
  }
})

compared to what it used to be:

new InjectOptionsPlugin({
  loaders : {
    "workerize-loader" : {
      name : dev ? "[path][name]" : "[path][name].[contenthash]"
    }
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant