Fork me on GitHub
#reagent
<
2015-08-19
>
Pablo Fernandez07:08:53

henryzhu: but why is nodejs needed at all? wouldn’t phantomjs be enough? why do you need a server side javascript framework? I’d rather serve stuff with clojure than javascript.

Pablo Fernandez07:08:52

I have clojurescript project, starting from the reagent template (https://github.com/pupeno/proclodo-spa-server-rendering). I commented out all clojurescript code but in the compiled code I still get this line: if(typeof goog == "undefined") document.write('<script src="js/out/goog/base.js"></script>’); I’m trying to get rid of it to attempt running my cljs code in nashorn, which doesn’t implement document. Any ideas where that line is coming from?

darwin07:08:00

@pupeno: use :compiler { :target :nodejs}

Pablo Fernandez08:08:33

darwin: nodejs doesn’t implement document and window?

darwin08:08:10

no, it doesn't

darwin08:08:28

even if it did, it has require, to include scripts, not a script tag

Pablo Fernandez08:08:39

Good to know. That further reduces my desire to use nodejs vs nashorn.

Pablo Fernandez08:08:12

Somehow, omelette avoids document without targeting nodejs (https://github.com/DomKM/omelette)

darwin08:08:26

hmm, I don’t have experience with nashorn, but I think that it has document and window

darwin08:08:59

maybe you just have to bootstrap it somehow

Pablo Fernandez08:08:45

darwin: I now for a fact it doesn’t. Not sure if there’s a hack to add it, but I know other people had to work-around that.

Pablo Fernandez08:08:09

Now the files contain a few calls to goog, which is not defined 😕

darwin08:08:26

I don’t understand how is omelette using nashorn, it is not obvious from the sources

darwin08:08:03

I think the readme is wrong, omelette is using clojure on backend and clojurescript on frontend, no nashorn

Pablo Fernandez08:08:12

It’s definitely using nashorn and I run it in my machine and verified that javascript rendering is happening on the server.

Pablo Fernandez08:08:31

But I don’t understand why the generated javascript doesn’t call document and contains this:

Pablo Fernandez08:08:46

var CLOSURE_NO_DEPS = true; var COMPILED = false; var goog = goog || {}; goog.global = this; goog.global.CLOSURE_DEFINES;

darwin08:08:59

I think goog does not depend on js/document, so you can still include it in nashorn and then include your cljs sources

darwin08:08:00

they compile their cljs without :main compiler option, so public/assets/scripts/main.js contains goog and compiled sources, there should be no document reference

darwin08:08:21

what are your compiler options?

Pablo Fernandez08:08:59

darwin: I removed my :main attribute and that removed the call to document, but this also got rid of what was creating goog, so now I’m getting:

Pablo Fernandez08:08:01

javax.script.ScriptException: ReferenceError: "goog" is not defined in <eval> at line number 1, compiling:(handler.clj:16:3)

darwin08:08:49

add :optimizations :whitespace

darwin08:08:42

this will tell cljs compiler to create one file, now you are with :optimizations :none, so cljs compiler is creating a bunch of files, and including them with document.write(“<script…>”)

darwin08:08:02

maybe you also need that :output-to and :output-dir

darwin08:08:16

this will include goog into that one file

Pablo Fernandez08:08:53

ohhh… simple_smile I should have tried that. Thank you darwin.

Pablo Fernandez08:08:09

figwheel requires optimizations set to none 😞

darwin08:08:12

ok, then set it to :none and write bootstrap script by hand, eval goog/base.js first and then deps.js and then your cljs sources

darwin08:08:03

just look what gets generated by your :optimizations :none and rewrite the main script for nashorn