Fork me on GitHub
#shadow-cljs
<
2018-02-13
>
justinlee04:02:06

i’m trying to use PDFJS, which uses a web worker. the web worker is already distributed in the pdfjs-dist npm module under build/pdf.worker.js. what’s the right way to tell shadow-cljs about that file and that it need to be served during development and copied & minified during production?

justinlee04:02:35

I see the 6.4 Web Workers in the manual, but that is for cljs code, i think

thheller09:02:23

@lee.justin.m when I npm install pdfjs there is no such file?

mjmeintjes09:02:43

Hi. I seem to remember that there was a way to see how much size each library is adding to the total size of the release build using shadow-cljs. Is that a thing, or am I mis-remembering?

mjmeintjes09:02:08

Great, thanks. Exactly the post I was searching for.

thheller09:02:04

Haven't tested this in a while. might totally not work anymore 😛

mjmeintjes09:02:39

No worries, just glad I'm not going mad as I was sure I had seen it somewhere but couldn't find it anywhere.

thheller09:02:56

yeah not added to the docs yet

thheller09:02:15

kinda want to have an actual visualization first 🙂

thheller09:02:17

@lee.justin.m ah I looked at the wrong package. from what I can tell you don't need to use their bundle but instead you create a (ns your.app.worker (:require ["pdfjs-dist/lib/core/worker"])) and then let shadow-cljs build it for you

thheller09:02:36

but you can just (:require ["pdfjs-dist/build/pdf.worker"]) as well

justinlee17:02:40

@thheller so I thought with web workers you typically have to specify a uri in the worker constructor, which then goes and fetches the source at that uri and then runs it. in javascript all I do is

const PDFJS = window.PDFJS;
PDFJS.workerSrc = '/pdf.worker.js';
and then I make sure that the pdf.worker.js bundle is available to be served. so if I just straight require it, won’t that just include the worker source rather than allowing it to be run in a new worker? or is there more shadow-cljs magic here?

justinlee17:02:53

for what it is worth: i think it would be really cool to have shadow-cljs build it for me since the optimizations might be better. i was just trying to do it the easy way first

thheller17:02:44

so the "trick" with web workers in shadow-cljs is that is uses the code splitting

thheller17:02:09

meaning that code used only by the worker will also only be loaded when the worker is started

thheller17:02:41

the file that :web-worker true generates is a standalone worker file, ie. you call it with the webworker constructor

thheller17:02:09

I expanded the webworker section with an example

theasp17:02:26

Hmm, new error from the closure compiler in 2.1.7:

Closure compilation failed with 1 errors
--- node_modules/dialog-polyfill/dialog-polyfill.js:692
this language feature is only supported for ECMASCRIPT6 mode or better: block-scoped function declaration. Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT or higher to enable ES6 features.

thheller17:02:07

the "problem" with the pre-built pdfjs.worker.js is that it basically doubles the code your user has to download

thheller17:02:18

first the normal pdfjs and then the worker file

thheller17:02:35

code splitting would be better but I don't know exactly what pdfkit expects from the worker

thheller17:02:31

@theasp that worked before?

theasp17:02:46

Yeah, on Friday 🙂

theasp17:02:54

and before...

thheller17:02:05

which version?

thheller17:02:04

ah nvm got it

thheller17:02:16

weird thing is I set ECMASCRIPT_NEXT language mode

thheller17:02:39

which is way past ES6 so no idea why it wants es6

theasp17:02:57

I was using 2.1.4 on Friday

theasp17:02:03

Yeah, I was reading that

theasp17:02:35

Either way, I blame Google

thheller17:02:39

yeah I upgrade to the newest closure compiler verison in 2.1.7

thheller17:02:53

it had some improvements I wanted but I guess also some new bugs

theasp17:02:09

Said anyone who upgraded anything ever

thheller17:02:11

I'll see if I can figure something out

justinlee18:02:37

i read through the modules section again. if i understand correctly: i should create an empty cljs file for the worker that includes the entry point for the worker code. then declare that file as a web worker module and shadow will be able to serve it and pdfjs will be able to use it

thheller18:02:11

I don't know about pdfjs but yes thats the idea

thheller18:02:33

gotta love those helpfull errors from closure

thheller18:02:35

--- null:-1
Missing externs definition for Symbol. Did you forget to include the ES6 externs?

theasp18:02:23

ECMASCRIPT_NEXT for output, or input?

thheller18:02:46

forgot that I acutally set it to ES5 for node_modules files

thheller18:02:01

but if I set it higher I get the error above

thheller18:02:20

babel in theory is used for everything es6+ in node_modules for reasons such as this

thheller18:02:34

but the file is not detected as es6 and AFAICT it isn't either

thheller18:02:45

don't really understand what its complaining about

theasp18:02:44

I don't understand why we still need a dialog polyfill in 2018

thheller18:02:27

to be honest I had no idea that a dialog api even existed

thheller18:02:59

well .. I'm just going to bump the language in

theasp18:02:17

I don't think it does anything you couldn't do manually

thheller18:02:06

yeah I've always done dialogs manually. takes 5 lines of code or so. no idea why you'd need a standard api for that

theasp18:02:03

It's supposed to handle focus and modalness in an accessible way

thheller18:02:39

yeah I guess its a common enough thing to make it standard

thheller18:02:40

@theasp pushed 2.1.8 which seems to fix it

justinlee18:02:49

do you use joker as a linter? it is cranky because of the extension to the ns and I don’t think it is extensible in thatway

thheller18:02:15

everything except :default is standard clojurescript so it should support that

thheller18:02:25

but no I don't use it

justinlee18:02:40

i think it doesn’t like the strings

theasp18:02:57

@thheller My mystery console.clear() call is no longer happening.

thheller18:02:09

I actually added a (js/console.clear) to my :before-load hook. I kinda like it.

thheller18:02:31

but not really sure if I should add it as an option. seems fine when done in :before-load

theasp18:02:37

Yeah, probably shouldn't

koz21:02:49

@thheller just wanted to let you know that after upgrading from 2.1.6 -> 2.1.8 (2.1.7 didn’t compile) I am running into some issues where NPM deps are no longer coming in correctly (some libraries that I’m requiring are now resolving to undefined)