How to deal with webworker urls in js.Batch?

Howdy,

I’m currently trying to convert a project from a messy `js.Build` setup to a more streamlined js.Batch configuration. The old build uses several `js.Build’ calls to split the code into several parts and employs the `@params` systems for communication between them. A common use case is a WebWorker that needs the script url. The fingerprinted url is passed through that way.

Unfortunately that does not seem to work with `js.Batch`. When I try to extract the url, the build breaks as many files are no longer build:

{{- with .Group "main" -}}
  {{- $gr := . -}}
    {{- range resources.Match "js/main.js" -}}
      {{- $file := resources.FromString "js/x-main.js" .Content -}}
      {{- $worker := index (index $batch.Build.Groups "search-worker") 0 -}}
      {{- with $gr.Script (path.Base $file.Name) -}}
        {{ .SetOptions (dict "resource" $file) }}
      {{- end -}}
  {{- end -}}
{{- end -}}
...

Is this something that has already come up and a common solution is established?

I’ve read that `esbuild` should be able to handle this use case by using URLs that are automatically transpiled correctly when hashing is applied, but the Hugo integration does not seem to support that. Thanks.

Where have you read that? A link would be great.

This is the issue I have read WebWorker support? · Issue #312 · evanw/esbuild · GitHub

So, currently I suspect you need to do something ala hugoTestProjectJSModImports/assets/js/main.js at 7d79d6b7234028ca508d11fcb540ff5b299ecc00 · gohugoio/hugoTestProjectJSModImports · GitHub

When thinking about this, i think we could possibly do a better job of supporting this in js.Batch, but that’s non-trivial and not on my TODO list at the moment.

esbuild standalone seems to be able to perform the necessary replacements when hashing during deployment according to the OP.

EDIT: On 2nd thought, might be specific to angular though.

Understood. As always, thanks much for your support!