Skip to content

Commit 8ae47f5

Browse files
authored
Add webworker section to webpack guide (#369)
1 parent 1ca6a7f commit 8ae47f5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

content/guides/webpack.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,29 @@ clj -M -m cljs.main -co build.edn -O advanced -v -c -s
173173
```
174174

175175
That's it!
176+
177+
[[webworkers]]
178+
== Building Webworkers
179+
180+
When building webworkers with `:target :bundle`, you use webpack (or your
181+
preferred bundler) to add the webworker bootstrap.
182+
183+
So your build's `:target` will still be `:bundle` (not `:webworker`), but you
184+
will tell your bundler to build a webworker. For example, with webpack you add the
185+
`--target=webworker` argument to your `:bundle-cmd` entries.
186+
187+
You also need to define `cljs.core/*global*` as `"self"` (as opposed to
188+
`"window"` in browser builds).
189+
190+
An example `build-webworker.edn` might look like:
191+
192+
[source,clojure]
193+
```
194+
{:main hello-bundler.webworker
195+
:output-to "out/worker/index.js"
196+
:output-dir "out/worker"
197+
:target :bundle
198+
:bundle-cmd {:none ["npx" "webpack" "out/worker/index.js" "-o" "out/worker/main.js" "--target=webworker" "--mode=development"]
199+
:default ["npx" "webpack" "out/worker/index.js" "-o" "out/worker/main.js" "--target=webworker"]}
200+
:closure-defines {cljs.core/*global* "self"}} ;; needed for advanced
201+
```

0 commit comments

Comments
 (0)