Fork me on GitHub
#shadow-cljs
<
2022-07-19
>
agorgl09:07:18

Hello there! Just started my first clojurescript project! I see that for js npm dependencies the usage is pretty straightforward (just a require in the ns), but what about asset related dependencies like normalize.css? How do I link it in my index.html? Is there any kind of preprocessor?

thheller12:07:06

shadow-cljs does not (yet) support any CSS processing so you need to use external tools (eg. postcss) for that

Aspirational15:07:31

Hi. I have some issues with hot reloading. Tested it with custom var e.g. js/Date.now. When I change some text in my reagent component, shadow recompiles but I do not see my changed text within the component, but the component is re-rendered and the timestamp changes. Please look at the screenshot

thheller15:07:12

can't see how you are using this so can't help much. maybe this helps https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html, lists a few common gotchas

thheller15:07:47

where and how is home-panel used is the question?

Aspirational17:07:32

I have read "list with few common gotchas" and tried them. But I still can't figure it out. I have attached my app lifecycle. It's simple but I can't make hot reloading work fully. reagent triggers rerender. timestamp is changing but other component text changes only after full page reload

thheller17:07:41

so since you are deref'ing the current route there I assume that the function is in there

thheller17:07:12

and that is the problem. you put the function in the atom in some place, which remains the function it was when it was put in

thheller17:07:17

since only the namespace reference is updated

thheller17:07:41

that would be the Holding Code references in State described in the blog post

🤓 1
🔦 1
❤️ 1
Mitul Shah16:07:11

Does anyone use phosphor-react with shadow-cljs? We use it, but since there’s no tree-shaking in shadow, the package gets fully imported

Mitul Shah16:07:59

i’ve tried phosphor-react/icons/IconName :default IconName but no luck

thheller16:07:18

no luck means?

Mitul Shah16:07:39

get error that file couldnt be found

Mitul Shah16:07:38

i scanned through similar questions in the slack and the packages have alias (@) imports, wonder if that makes a difference

thheller16:07:01

looks over the actual file structure of the package

thheller16:07:22

either in your node_modules/phosphor-react folder or online via https://unpkg.com/browse/[email protected]/ for example

thheller16:07:34

don't look at the source, look at the actual published package

thheller16:07:11

I see some files in dist/icons? so that would be phosphor-react/dist/icons/...

Mitul Shah16:07:10

The required JS dependency "phosphor-react/dist/icons/Info" is not available,
same error

thheller16:07:01

because thats not the filename

thheller16:07:12

just put in the entire filename including the extension(s). thats all it is, looking for a file in the package

Mitul Shah16:07:09

wooo, phosphor-react/dist/icons/Info.esm.js works thank you

Andrew Lai17:07:08

Hi Shadow channel! We’re building a re-frame app with Shadow and wanted to add an image to a React component. In JS-land, I believe you can directly import the image, using, for example:

import logo from '../logo.svg';
https://stackoverflow.com/a/47487760 I found this thread, mentioning that this can be done with Shadow in React Native. Should we expect this solution to also work with React/JS? Is there any other preferred method for including an image? (js/require "./../../resources/img.png") https://clojurians.slack.com/archives/C6N245JGG/p1571922982374700

thheller17:07:42

no, that is specific for react-native

thheller17:07:32

I generally just put images and stuff into my public folder and reference them by name, so just [:img {:src "/path/to/file.png"}] or whatever. no require or anything else to find the image.

Andrew Lai17:07:34

Cool! Will that include the images at build time, or do they need to be served from a Backend to be accessible?

thheller17:07:25

no, images are never included in a build. that would make it absurdely large

Andrew Lai17:07:42

Gotcha. I’m definitely not an expert in JS/React land. When someone does this statement in JS from a create-react-app project, import logo from '../logo.svg';, does that not bundle the image into the build? I don’t have a strong enough mental model of how the image asset gets included, and I’m not sure where to look to build that model. I’m reading https://create-react-app.dev/docs/adding-images-fonts-and-files/ for trying to build my mental model. What I understood was that Images do get directly included into the build. But is that just unique to how create-react-app works (and shadow works differently)?

thheller17:07:32

in case of svc it might get inlined but most of the time this just gives you a path where to find that logo

thheller17:07:45

create-react-app (webpack) then moves the file to that place

thheller17:07:29

for your own code it works just as well to just keep the file in that place from the start 😉

Andrew Lai17:07:15

Gotcha. So what I’m taking away is that being able to import non-SVG image assets directly is a feature of how Webpack bundles Javascript modules, and it relocates them after bundling. In contrast, importing svgs may just directly inline the image, and that’s also a Webpack feature.

thheller17:07:46

I don't actually know if it ever inlines svgs, just saying its possible

thheller17:07:58

but yes, its a webpack feature

👍 1
thanks3 1