-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
:optimizations :advanced not wrapping output by default #64
Comments
:optimizations :advanced
not wrapping output by default
:optimizations :advanced
not wrapping output by default
This is a bug with either cljs compiler or documentation, I'll ask David. |
The docs were wrong. Default is false. |
Reopening this to say that :output-wrapper should be true by default on :advanced... emezeske/lein-cljsbuild#201 |
That issue is quite old so I don't know how well it does hold now. Cljsbuild does indeed seem to use output-wrapper with advanced compilation. |
I think it's pretty important to set this on, since it's a super obscure source of bugs (globals clattering) and people switching from lein-cljsbuild (like me), which does have it on, are going to suddenly have potentially broken builds on :advanced. |
If this is so important, I think the default option should be set on ClojureScript compiler itself instead of on build tool. This should be reported here: http://dev.clojure.org/jira/browse/CLJS (I did a quick check and did not see similar issues) Cljs wiki used to say this is enabled when using advanced compilation, but as this is not the case, I remeved the mention: |
Looks like ClojureScript default is not going to change: http://dev.clojure.org/jira/browse/CLJS-1520 |
Would it be enough to create wiki pages "Differences to Lein-cljsbuild" and "Common problems" and list this there? Would need some description of the problem and cause as I have not seen this myself. |
Yeah it would definitely be nice to have some page like that. Basically without :output-wrapper, advanced compilation creates global variables like "aE", "bC", etc (minimized) and these may interfere with existing globals on the page. |
So it requires some non-Closure/Cljs JS code to trigger this? Minified code from foreign-libs (cljsjs) can probably trigger this? |
I think foreign-libs are fine (if they go through the advanced compilation with the entire codebase). It's more of a problem when putting the compiled js on a page with other non-cljs code (Wordpress for example) and causing conflicts. |
I think @Deraen's description is accurate. CLJSJS code can certainly trigger these kinds of failures. Might be worth considering adding a warning to cljs task when any deps within the CLJSJS group are used and output-wrapper is not enabled. Special casing things is bad I guess but depending on how easy it is to integrate we might just do it? @kanwei foreign-libs don't go through advanced compilation but instead may provide their own minimized builds. Only sources properly annotated for the closure compiler can be compiled with advanced and most JavaScript libraries are not. |
I just ran into this issue. If you use a lot of third-party javascript libraries, you're very likely to run into weird errors because those libraries overwrite two-letter js globals. What's worse, these show up only intermittently because variable assignments change quasi-randomly for every build. Although this behavior is documented, it's hard to know what to google for or that the place to look is the cljs compiler options. I see three ways of fixing this:
I'd be happy with each option (possibly favoring 1). If there's a consensus, I'll happily prepare a PR. |
I'm inclined to vote for 3 just because there's no clearly right way. Also sticking to compiler defaults as defaults makes things more predictable most of the time I guess. We could show the warning for all optimization settings but |
I love the ascii art idea |
@Deraen @pesterhazy — replying to your Slack convo: Juho said:
I don’t think that’s something most people are aware of and thus think adding this warning is a great idea. If you use advanced and external JS and are not aware that you should be setting I also don't consider this breaking since it doesn't affect the result (i.e. the compiled JS) of the task. Setting |
I've had exactly the same issue. I've spent a lot of time to finally stumble on this ticket and solve my problem. I don't know what the correct decision should be, but something must be done to save people's minds. I was so desperate I even tweeted about it: https://twitter.com/danielszmu/status/878317585820819456 |
Keeping the defaults of the build tool aligned with the defaults of the compiler is a good, general principle.
|
@danielsz I have been arguing for it to be on by default as well, thank you for voicing your input too! It's definitely a bad experience for first-time users. |
@Deraen what do you think about setting We could document differences to default compiler options in the task docstring + Readme. |
fix #64; set output-wrapper true if unset and advanced compilation
Hey, I recently started a new ClojureScript project using boot-cljs. Everything worked fine, except that I noticed that when I compiled with the
:optimizations :advanced
mode of the closure compiler themain.js
file that came out clobbered my global namespace.I was able to find the :output-wrapper parameter of the clojurescript compiler, and turning it on in my
build.boot
file fixed the issue. However, my understanding is that with the advanced compilation options, this should be turned on by default.I've included my
build.boot
file below, in case it helps. Very much vanilla stuff though. The only change between the old and new versions is the:compiler-options
on the last line of the new one.Old
New
The text was updated successfully, but these errors were encountered: