Fork me on GitHub
#shadow-cljs
<
2020-03-07
>
tianshu08:03:20

can I make shadow-cljs only bundle parts of javascript that is required? or should I use double bundle with webpack instead?

thheller08:03:47

@doglooksgood not sure what you mean. shadow-cljs always only bundles javascript that is required?

tianshu09:03:54

@thheller I see, I means sometime a javascript file may include other files. like

require A from "a";
require B from "b";

module.exports {
  a: A,
  b: B
}
since there's an object that contains a and b, If I require this file in cljs, both a and b will be bundled no matter I use them or not.

tianshu09:03:23

But in library like https://github.com/FortAwesome/react-fontawesome#explicit-import It is said, when using webpack, explicit import will let you to only bundle what you need. import { faCoffee } from '@fortawesome/free-solid-svg-icons' only include the faCoffee, even though '@fortawesome/free-solid-svg-icons' represent a index.js that require all files.

thheller10:03:39

@doglooksgood yes that style is not supported. however you can probably just do ["@fortawesome/free-solid-svg-icons/faCoffee" :as faCoffee] (maybe :default not :as) to get the same effect?

tianshu10:03:38

Yes, I can use this way

tianshu10:03:45

Is it possible to use closure compiler to optimize javascript library, or how can I know if a library can be optimized by closure compiler?

thheller10:03:50

if the library is purely strict ESM and only have strict ESM dependencies then in theory it can be optimized by the closure compiler

thheller10:03:57

in practice at least on npm that never happens

thheller10:03:32

eg. react/react-dom is not provided as strict ESM

tianshu10:03:49

ESM means ES module?

tianshu10:03:15

I just curious about, what if, ClojureScript do dead code eliminate by its compiler and don't rely on closure library and closure compiler ? is it a good direction in your sight?

thheller10:03:48

in theory that would be nice yes. in practice it doesn't work with a very large percentage of npm packages (I'd guess 90%+)

thheller10:03:34

if they ever get their act together and follow the standards then maybe that gets better over time. today it is not practical

tianshu10:03:27

emm, why you think it doesn't work with most npm packages?

thheller10:03:58

I don't think .. I know 😛

thheller10:03:25

reasons vary .. either they include "dynamic" code that isn't compatible with the closure-compiler

thheller10:03:46

most of them ship as commonjs without strict ESM compatibility

thheller10:03:57

or just include some transpiled garbage ...

thheller10:03:16

you can try setting :js-options {:js-provider :closure} in your build config

thheller10:03:32

that will make everything go through closure-compiler :advanced compilation

thheller10:03:42

it has not worked in a single build I have tried

thheller10:03:56

you can sort of get it to work with lots of manual tuning

thheller10:03:14

but that is rarely worth the effort

tianshu10:03:26

If react and react-dom not work with closure compiler, my build will never work:joy:

tianshu10:03:16

If ClojureScript drop closure compiler, and act like a babel transpiler, is it possible?

tianshu10:03:51

typo, label -> babel

thheller10:03:52

sure, if you want to drop the closure-compiler. I have no interest in that.

tianshu10:03:25

I don't see closure library is wildly used by clojurescript programmers and libraries. It almost provide everything but just not be considered as mainstream, and looks like few people and libraries use it.

thheller10:03:00

its not about the closure-library. it is about the closure-compiler.

thheller10:03:35

most people see it as a negative for some reason. for me its just positive so I have no interest whatsoever in efforts to replace it.

tianshu10:03:37

I think closure library is part of the value of closure compiler?

thheller10:03:00

yes, it is a bonus

tianshu10:03:44

you mean closure compiler provide optimizations, that's good choice, no matter use closure library or not, you will still use closure compiler?

tianshu10:03:59

make sense.

thheller10:03:46

FWIW I think it would have some value if the CLJS compiler just emitted strict ESM code

thheller10:03:53

that would open up more tool options

thheller10:03:21

but I would under no circumstance get rid of the closure-compiler in my builds

thheller10:03:19

but many things we love in clojurescript and rely on are not possible with strict ESM code (eg. hot-reload, REPL) so it would need to be transpiled to something else to enable that

thheller10:03:27

which brings us basically back to where we are now 😛

tianshu11:03:09

Three years before, the hot-reload is a magic, but know it's just a standard. Almost every JavaScript toolchain support that.

thheller11:03:20

dunno ... last time I tried it really didn't work all that well

thheller11:03:37

but its been a while so presumably things got better

tianshu11:03:39

I don't have any experience of F# and Fable(F# on JS), but how fable work is just implement a loader, and configure it in webpack.

{
        test: /\.fs(x|proj)?$/,
        use: {
          loader: "fable-loader",
          options: {
            babel: babelConf
          }
        }
}

thheller11:03:02

you seem to see webpack as a positive. I don't 😛

thheller11:03:33

if you want to build a loader go do that. many people would be interested in that I think.

tianshu11:03:26

I don't think webpack is positive, it's too complex. But sometimes I still need that simply import some css or fonts.

thheller11:03:31

I made comments about why I'm not interested in webpack loaders in the past so you should be able to find it

Aleed17:03:55

just an fyi for others, I was curious and found the discussion here: https://github.com/thheller/shadow-cljs/issues/123#issuecomment-340246560

thheller11:03:04

yeah we need a good tool for importing css or fonts

tianshu11:03:22

there are several levels, for I) I don't want use JS syntax, II) I don't want use JS build tool, III) I don't want use JS lib repository(npm), IV) I don't want JS dependency

thheller11:03:16

yep, some npm access is nice but it is never my preferred choice 😛

frozar14:03:13

Hi, I'm trying to put in place some test and I would like to know which namespace shadow-cljs found when it scan my project. Is there a way ask which test namespace has been found by shadow-cljs?

thheller16:03:33

@fabien.rozar ask how? I mean do you want to ask "does namespace x.y.z exist?", meaning direct lookup by name?

tekacs20:03:33

For what it's worth I just use shadow.resource to load CSS into my app

tekacs20:03:10

I wrote something small akin to style-loader and just use that

tekacs20:03:21

should be easy to do something very similar for fonts, etc.

tianshu20:03:19

@tekacs thanks! The idea is load the file in macro and insert into <script> in runtime?

tekacs20:03:39

so rc/inline pulls the file into the build

tekacs20:03:49

and tracks it as an incremental depenency

tekacs20:03:56

so that if you change the CSS it instantly reloads

tekacs20:03:14

and then the rest of the code simply puts it into the head as a script tag with a sourcemap

tianshu20:03:16

great, how about the untrack? I mean, when my code don't rely on a CSS file

tekacs20:03:11

sorry, what does that mean?

tekacs20:03:23

you mean unloading it, or ensuring that it's not pulled in?

tianshu20:03:02

I guess shadow use this internally, so it should be okay.

tianshu20:03:39

finally I could get rid off webpack.