# `mix maplibrex.copy_worker`
[🔗](https://github.com/CountlinkX-Solutions/maplibrex/blob/v0.4.0/lib/mix/tasks/maplibrex.copy_worker.ex#L1)

Copies the worker files of maplibre-gl 6 into the application's static
assets, where `setWorkerUrl` points MapLibre at them.

    $ mix maplibrex.copy_worker [--from DIR] [--to DIR]

maplibre-gl 6 starts its worker from a separate file,
`maplibre-gl-worker.mjs`, which esbuild does not copy into the build. This
task copies it, and `maplibre-gl-shared.mjs` (which the worker of releases
before 6.13 imports) when the installed maplibre-gl has it, from `--from` to
`--to`, creating `--to` if needed. Running it again copies the files again
and changes nothing else.

With maplibre-gl 5, which carries its worker inside its own bundle, or when
maplibre-gl is not installed, it copies nothing, says why in one line and
succeeds. So it is safe in the asset aliases of any application, in
`mix.exs`:

    "assets.build": ["compile", "tailwind my_app", "esbuild my_app", "maplibrex.copy_worker"],
    "assets.deploy": [
      "tailwind my_app --minify",
      "esbuild my_app --minify",
      "maplibrex.copy_worker",
      "phx.digest"
    ]

## Options

  * `--from` - the `dist` directory of the installed maplibre-gl.
    Defaults to `assets/node_modules/maplibre-gl/dist`
  * `--to` - where the application serves `app.js` from. Defaults to
    `priv/static/assets/js`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
