Fork me on GitHub
#clojurescript
<
2019-06-04
>
roman01la13:06:08

Does anyone know how to exclude https://github.com/bhb/expound when compiling with advanced optimizations?

roman01la13:06:55

Simply requiring it and wrapping usage sites with (when ^boolean goog.DEBUG ...) doesn’t help

roman01la14:06:04

Perhaps should hack around it with :preloads

aisamu06:06:04

We've had reasonable success removing things with macros for the code + :strip-type-prefixes for ns entries. (shadow-cljs only, https://shadow-cljs.github.io/docs/UsersGuide.html#_code_stripping)

roman01la14:06:10

Wonder what are the general workarounds for non-DCEable code in cljs

Olical14:06:55

Would a require wrapped in a macro do it? (a macro that toggles content based on some compile time flag)

roman01la14:06:57

@olical There’s no require in cljs as in JVM Clojure AFAIK, it works only in REPL

roman01la14:06:02

it would mean dynamic require in adv compilation mode, which is a different thing (cljs.loader)

Olical14:06:51

Ah yeah, that's only REPL. But could you condition an ns form that would be picked up by the compiler?

roman01la14:06:34

yeah probably, but honestly :preloads looks better for this IMO

Olical14:06:46

(core/defmacro require
  [& args]
  `(~'ns* ~(cons :require args)))
require is just that anyway

Olical14:06:56

Not sure what preloads is, so maybe 😄

roman01la14:06:01

afaik ns form in cljs is a special form, it’s translated directly into Closure’s module definition syntax, so not an option

mfikes15:06:20

Yeah, you can't really make ns forms be dynamic in any way... they are consumed during compilation.

Olical16:06:41

That was my point though really, that you want to toggle at compile time, so you could macro out a ns form based on compilation level. Maybe...?

Olical16:06:57

And then macro out code that depended on that require.

oconn18:06:20

Question about modules. If I compile a project using the modules options like;

{:output-dir "out"
 :optimizations :simple
 :modules {:a {:entries #{app.feature.a}
               :output-to "out/a.js"}
           :b {:entries #{app.feature.b}
               :output-to "out/b.js"}}}
I seem to get an error when importing any Closure lib inside that module. goog is not defined at file-name.js:17 If I use main and output-to this is not the case;
{:main app.feature.a
 :output-dir "out"
 :output-to "out/a.js"
 :optimizations :simple}
Is there a simple way to include the goog namespace in each module?

dnolen18:06:25

@oconn that doesn't seem right to me

dnolen18:06:43

something else is probably wrong

oconn18:06:25

Ok, will continue to investigate

dnolen18:06:03

@oconn I recommend making a trivial project where you try the same thing

dnolen18:06:12

it'll take a couple of minutes and remove a lot of variables

dnolen18:06:24

if you can reproduce that on a recent version of ClojureScript then that's a bug

dnolen18:06:40

also makes it easy for someone else to reproduce

oconn18:06:57

This is in a new project so it should be easy to experiment with. I’ll try and older version of cljs as well

dnolen18:06:58

you're probably not requiring the right files in your page

dnolen18:06:43

you might have missed a step

oconn18:06:50

Yeah that’s what I was following

dnolen18:06:05

did you put the base file before your module file?

oconn18:06:58

<html>
    <body>
         <button id="button">Load Bar!</button>
         <script src="out/cljs_base.js" type="text/javascript"></script>
         <script src="out/foo.js" type="text/javascript"></script>
    </body>
</html>

oconn18:06:48

Is there a way to have that loaded automatically in each module?

oconn18:06:03

Each one needs to be deployed as it’s own js bundle

dnolen18:06:10

that's how Google Closure code splitting works and we just follow the rules

dnolen18:06:56

note that this isn't really a problem in practice - you can setup a routing thing

dnolen18:06:56

re: your problem, goog is not defined at file-name.js:17

dnolen18:06:04

this error doesn't line w/ anything you've said above

dnolen18:06:32

if you drop the error unmodified will be easier to suss out what's going on

oconn18:06:46

I can do that - so fwiw, I’m trying to create a number of js bundles that can be dropped into a page I do not control. I can do this by compiling each one separately without using modules, but I was thinking that would be an easier approach.

dnolen18:06:38

I don't know about easier

dnolen18:06:59

modules are designed for one thing and one thing only - managing time to load

dnolen18:06:13

if that's not a priority I wouldn't bother

oconn18:06:54

Cool - appreciate the help

dnolen18:06:02

I also don't understand why you would need to compile separately

dnolen18:06:20

again, based on what you've said - routing sounds like it would suffice

dnolen18:06:28

w or w/o code splitting

oconn18:06:42

Would like to keep the overall bundle size down since only one component could ever be loaded at time.

dnolen18:06:20

ok just remember if the component is very simple code splitting isn't going to help as much as you would like

dnolen18:06:47

code splitting really only makes a significant impact on fairly complex SPAs where there's a fairly complex set of components in different logical views

dnolen18:06:14

if that's not the case

dnolen18:06:33

you're going to end up with 100K+ gzipped base and 2-5K modules

oconn18:06:33

yeah, I think that’s what I was missing. Thanks again for the help and all your work with CLJS

oconn18:06:31

yeah that’s the size I’m seeing with the final artifact.

dnolen18:06:39

right very little win 🙂

lxsameer20:06:48

hey folks, I have a ns form like (ns some-ns (:require [ns1.ns2])) and i'm not using ns1.ns2 at all. Does cljs compiler include ns1.ns2 in the final optimized build ?

thheller20:06:26

yes, but depending on the code written there it may be fully deleted if nothing is used

lxsameer20:06:40

so it depends

lxsameer20:06:43

and I can't be sure

thheller20:06:08

shadow-cljs can generate detailed build reports so you can easily check if something is included that shouldn't be https://shadow-cljs.github.io/docs/UsersGuide.html#_build_report

lxsameer20:06:30

cool thanks man

lxsameer20:06:07

is it possible to call function from another namespace in the same project without requiring their namespace ? something like this in nsA, (other-ns/some-fn ...)