Fork me on GitHub
#shadow-cljs
<
2018-08-13
>
hlolli00:08:11

I may be wrong, but I feel like the returned build-state from :compile-prepare and/or :compile-finished isn't ending up in the source code, be it watch or release. Just doing string/replace on the string of js resource (nested under :sources [:shadow.build.npm/resource "libcsound/libcsound.js"] :source)

thheller08:08:57

@hlolli what I would suggest is creating a libcsound/libcsound_browser.js and then in package.json use a "browser":{"libcsound/libcsound.js": "libcsound/libcsound_browser.js"} override

thheller08:08:21

this will cause pretty much all JS build tools (including shadow-cljs) to include the libcsound/libcsound_browser.js when building for the browser

thheller08:08:26

but otherwise use the node version

hlolli09:08:25

@thheller didn't know about this funtionality with "browser", sweet. Was hoping to avoid having two copies of that file. As it would essentialy mean two copies of the wasm binary as well. Is what I'm trying to do, in build-state, assoc-ing-in :sources a new source string, possible?

thheller09:08:15

yes but not recommended because you destroy source maps that way

hlolli09:08:28

here my hook

(defn wasm2datauri
  {:shadow.build/stage :compile-finish}
  [build-state & args]
  (let [resrc   [:shadow.build.npm/resource "libcsound/libcsound.js"]
        src     (get-in build-state [:sources resrc :source])
        wasm    (string/trim (:out (sh "node" "libcsound/datauri.js")))
        new-src (string/replace src "libcsound.wasm" wasm)]
    (assoc-in build-state [:sources resrc :source] new-src)))

hlolli09:08:59

ah ok, it's only one line, so won't create a new line.

thheller09:08:23

can't do it in :compile-finish though

thheller09:08:31

but I really do not recommend doing it this way

thheller09:08:43

it messes with the cache as well

hlolli09:08:16

ah I see.. maybe only in release, as flush?

hlolli09:08:36

no it uses cache too I guess

hlolli09:08:28

can I calculate sha256sum of the string and replace it with what the cache hash value?

thheller09:08:28

why reinvent the wheel though? "browser" is exactly for cases such as yours?

thheller09:08:19

do you have the code available somewhere? I kinda don't understand what exactly you are trying to do

hlolli09:08:23

I'm just trying to avoid having two different files, just create the file/string during compilation

thheller09:08:43

why does it have to be during compilation though?

thheller09:08:52

why not do it before?

thheller09:08:12

trying to do this as part of the compilation itself just makes it 100x more complicated

hlolli09:08:01

then I have two 6mb files, 1 is js bindings files from emscripten, another .wasm, and when the .js file gets 6mb with the base64 string, it's hell to open and edit.

thheller09:08:26

no I mean create the file before you run shadow-cljs

thheller09:08:47

node create-that-browser-file.js && shadow-cljs ....

hlolli09:08:57

haha of course

hlolli09:08:11

I can hook shadow to delete it after compilation

thheller09:08:54

if the extra file is a problem you could also create a secondary package?

thheller09:08:00

libcsound-browser or whatever

thheller09:08:10

and include that via :resolve settings

hlolli09:08:33

yup, that's what I previously did.

hlolli09:08:38

and that works too

hlolli09:08:19

so I'm only trying to simplify, by having 1 copy of every file that I need.

thheller09:08:44

what you are trying to do doesn't exactly sound simple to me

hlolli09:08:33

yes, I can see how you see that. And it's probably true.

thheller09:08:03

you could also use a CLJS macro and read the file directly during compilation

thheller09:08:26

but no idea if that works with the way the js bindings are setup

hlolli09:08:00

yes, didn't consider that, a macro. I guess a slurp can be evaled by a macro.

thheller09:08:59

I strongly suggest however that you do whatever you need to do BEFORE shadow-cljs compilation starts

thheller09:08:05

and then compiling everything normally

thheller09:08:28

doing it during compilation will just break in various ways

👍 4
hlolli09:08:30

yes, your suggestion above, just use package.json script and create the file before, sounds clean to me

pauld13:08:12

I have a lein project that I want to use shadow-cljs for, so I included [thheller/shadow-cljs "2.5.0"] in the project.clj deps. However now I get an Exception when I run lein cljsbuild once min:

thheller14:08:55

@pauld there is figwheel in that stacktrace and not shadow-cljs?

pauld14:08:30

I know, very strange.

thheller14:08:40

ah you have a user.clj that loads figwheel on startup

thheller14:08:56

the problem is an old closure compiler version

thheller14:08:09

check lein deps :tree

pauld14:08:03

ah! thanks - that fixed it

pauld14:08:14

I had an older clojurescript dep

pauld14:08:50

I'm wondering if I can run a build report on this lein project.

pauld14:08:10

npx shadow-cljs run shadow.cljs.build-report app report.html

thheller14:08:24

depends on the cljsjs deps. some may not work

pauld14:08:42

yeah I do get an error

pauld14:08:11

Caused by: /home/paul/.m2/repository/cljsjs/create-react-class/15.6.0-1/create-react-class-15.6.0-1.jar deps.cljs refers to file not in jar: cljsjs/create-react-class/production/create-react-class.min.inc.js

thheller14:08:31

thats an old reagent version I think

thheller14:08:57

it was fixed a while ago though.

thheller14:08:28

you can just exclude cljsjs/create-react-class from your deps for that one

pauld14:08:27

I will have to see where it gets pulled. It's a qlkit transitive dependency.

pauld14:08:11

[cljsjs/create-react-class "15.6.2-0"] [cljsjs/react "16.2.0-3"] [cljsjs/react-dom "16.2.0-3"]]

pauld14:08:43

Or is there newer version I should be getting? say from npm?

pauld14:08:56

I get the following error now:

hlolli14:08:06

@pauld I would use react and react-dom from npm isntead of cljsjs when useign shadow-cljs

pauld14:08:32

And what if the clojurescript library I use - uses it?

pauld14:08:56

can I do some :excludes to make the switch?

ClashTheBunny14:08:01

You can just provide it by providing the CLJS namespace.

ClashTheBunny14:08:50

That way, your dependent library gets react in the namespace it expects.

thheller15:08:20

you don't actually need those for the most common dependencies

thheller15:08:55

its just that one exception that had a buggy cljsjs release

thheller15:08:06

otherwise you don't need to exclude cljsjs dependencies

pauld15:08:34

yeah react stuff seems to work after npm install except:

pauld15:08:46

Caused by: The required namespace "cljsjs.material-ui" is not available, it was required by "qlkit_material_ui/core.cljs".

thheller15:08:25

yeah that would require one such wrapper

thheller15:08:23

(ns cljsjs.material-ui
  (:require ["material-ui" :as mui]))

(js/goog.exportSymbol "MaterialUI" mui)

thheller15:08:34

I'm not exactly sure what the global or npm package are for those though

thheller15:08:38

but FWIW since you want build-reports anyways. material-ui is one of those huge packages

thheller15:08:09

and its much much better to only include what you actually need.

thheller15:08:20

like @material-ui/core/Button

thheller15:08:45

but qlkit probably assumes that you use everything

pauld15:08:47

yeah... I read that somewhere

pauld15:08:27

I wonder how I would go about trimming down qlkit deployment size

pauld15:08:07

npm installing cljsjs dependencies, putting in excludes, wrapping where necessary and putting in only specific material-ui deps via npm install?

thheller15:08:10

In my example I posted a comparison for antd vs individual antd components

thheller15:08:38

and thats 1.6mb vs 350kb

thheller15:08:43

material ui is larger than that

thheller15:08:13

the problem is with qlkit. if that always imports the material-ui "meta" package which in turn includes everything else

thheller15:08:19

you won't get a smaller bundle

pauld15:08:58

so only option is to fork qlkit?

thheller15:08:44

the svg-icons are another megabyte or so I believe

thheller15:08:09

-rw-rw-rw- 1 thheller thheller 1007K Feb 27 17:59 material-ui.min.inc.js
-rw-rw-rw- 1 thheller thheller  1.4M Feb 27 17:59 material-ui-svg-icons.min.inc.js

thheller15:08:17

2.4mb total

thheller15:08:29

just due to those two requires

thheller15:08:03

for the SVG icons its really important to only import the ones you actually use and not everything

lilactown15:08:56

qlkit-material-ui.core is super small. you could probably rewrite it to only include what you need

thheller15:08:31

yeah I think you can take it out completely

thheller15:08:56

the only thing that seems to be relevant is the (ql/regsiter-component ..) call https://github.com/forward-blockchain/qlkit-material-ui/blob/master/src/qlkit_material_ui/core.cljs#L51

thheller15:08:17

so (:require ["@material-ui/core/Button" :default Button]) and (ql/register-component :button Button) may just work?

lilactown15:08:23

sounds like it, as long as the register-component is called before qlkit/mount

thheller15:08:04

doing that for all the components and icons you actually use seems to be best

thheller15:08:09

annoying but best 😉

pauld15:08:05

Also material-ui-svg-icons is now depreciated in favor of: @material-ui/icons

thheller15:08:33

yeah you can import each icon individually there too

pauld16:08:15

It could be a fun game to trim this down.

lilactown16:08:06

module keys can be namespaced right?

thheller17:08:10

well they can but the ns will be dropped

thheller17:08:56

why? what would it accomplish?

lilactown17:08:06

I know I’m going to run into an issue eventually where two different experiences might have similar components, e.g.: dashboard/livehelp homepage/livehelp I can simply use dashes instead of slashes, it’s not a huge deal. just aesthetically it would be nice to be able to namespace them

mhuebert19:08:03

hmm, would there be any harm in adding a build hook that goes before :configure, where I could modify :closure-defines?

mhuebert20:08:12

maybe I am just editing the wrong piece of the state

mhuebert20:08:24

ah. I was trying to modify :shadow.build/config, but those settings have already been locked-in elsewhere, so I can instead update-in build-state [:compiler-options :closure-defines]

thheller20:08:53

@mhuebert yeah you can do it in :compile-prepare

larshelg21:08:11

@thheller Just wondering about the react-native support. Is this supported or on the roadmap?

thheller21:08:34

@larshelg depends on what you expect to work. I do not use react-native myself and haven't done any work on the support in a while

thheller21:08:46

:npm-module will work but is sort of limited regarding repl/live-reload

larshelg21:08:48

Great, I will give it a try 🙂

larshelg21:08:55

Well it would be great with repl/live-reload support. I dont know how hard it would be to implement. But seeing that there is partial support for RN it would be great to have it on the roadmap.

thheller21:08:38

its on the roadmap yes. just don't know when I can get to it since I need to look into react-native stuff first

thheller21:08:58

last attempts always had me frustrated figuring out the metro details

thheller21:08:05

never could get source maps to work for example

lilactown21:08:04

thheller if I have time, I’d like to dig into the RN stuff. would you appreciate any help with that?

thheller21:08:09

any help is appreciated yes

larshelg21:08:13

I sure would appreciate it

thheller21:08:04

FWIW I think the only hurdle left were the source maps

thheller21:08:43

which however are very important but I couldn't even figure out if they are even supposed to work at all

thheller21:08:49

documentation on that subject is sparse

thheller21:08:06

https://github.com/facebook/metro/issues/104 nothing happened here so they still might not be supported

larshelg21:08:02

I see, but the hot reload is working?

thheller21:08:25

should be yeah

thheller21:08:37

not with :npm-module though

larshelg21:08:39

great, i guess no source maps means debugging is a nightmare, but still glad to hear that all the other stuff is working

thheller21:08:04

well with :npm-module you can just use the built-in RN reloading stuff

larshelg21:08:18

yeah, I´ll look into it