This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-04
Channels
- # aleph (10)
- # announcements (2)
- # babashka (2)
- # beginners (101)
- # calva (17)
- # cider (11)
- # clara (6)
- # clj-kondo (25)
- # cljsrn (33)
- # clojure (181)
- # clojure-dev (15)
- # clojure-europe (3)
- # clojure-italy (4)
- # clojure-nl (8)
- # clojure-uk (22)
- # clojurescript (111)
- # clojutre (58)
- # cursive (31)
- # data-science (1)
- # datomic (10)
- # emacs (6)
- # ethereum (1)
- # fulcro (20)
- # graalvm (3)
- # jackdaw (5)
- # leiningen (5)
- # off-topic (31)
- # re-frame (2)
- # reitit (10)
- # shadow-cljs (9)
- # spacemacs (16)
- # sql (8)
- # tools-deps (16)
- # vim (17)
If I have a combined front-end / back-end project, should I be marking all cljs dependencies in project.clj with :compile
or :provided
?
Typically you setup a separate cljsbuild
task that will produce it's own build into an output folder.
I would suggest looking at some sample template and setting up your project accordingly. https://clojurescript.org/guides/project-templates
Typically you setup a separate cljsbuild
task that will produce it's own build into an output folder.
I would suggest looking at some sample template and setting up your project accordingly. https://clojurescript.org/guides/project-templates
api.cljs is probably the most interesting for you - https://github.com/xapix-io/axel-f/blob/master/src/axel_f/api.cljs that’s how I shaped out api for JS runtime
and then the wrapper - https://github.com/xapix-io/axel-f/blob/master/axel_f.min.js.edn#L15-L65
for the reference - https://clojurescript.org/reference/compiler-options#output-wrapper
your are welcome)
fyi, this is what I'm trying to JS-ify: https://github.com/borkdude/sci/issues/92
:thumbsup: will have a deeper look to it, already spotted some places that can make outgoing bundle smaller. Just need a day or two for proper PR
@U04V4KLKC I pushed an initial version to npm: https://www.npmjs.com/package/@borkdude/sci#usage-from-javascript
I used your project as a template. If you have any guidance/PRs to reduce the size of the asset, more than welcome. No hurry.
I guess mori is one example. Should you compile to advanced or what is the best way here?
depends on what you intend the target to be? if its going to be used in browser builds you pretty much need advanced
yeah nobody is gonna want to include 2mb of JS which you'd probably get with :simple
depends on what you are trying to do exactly I guess? shadow-cljs has :node-library
support, although intented for node the release artifact works in browsers too https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-library
CLJS always bundles cljs.core
so it isn't great for libraries since :advanced
always presumes it optimizes the whole program not just parts of it
I'll maybe try to deploy sci to npm, so you can just use it from JS directly instead of using it from CLJS: https://github.com/borkdude/sci the advanced build is around 350kb, not that great for a lean browser app, but could be useful
thanks! added to this issue now: https://github.com/borkdude/sci/issues/92
Hey, I having some trouble importing from a cljc file. I am using @shadow-cljs. When I try and import macros from the file, it gives me an error saying that the macroexpanding of ns does not confrom to spec. I’m not sure what I am doing wrong.
Sounds like that error may be because of an incorrect ns
form. Do you know which file it is complaining about, and if so, what that ns
form looks like now?
This is the form it is complaining about
(ns components.nav.nav-component
(:require [components.header.header-component :refer [header-component]]
[main.routing.route-paths :refer [navigation-links]]
[components.nav.nav-item-component :refer [nav-item-component]]
[main.theme :refer-macros [use-style]]
))
the main.theme is the macros that it seems to dislike, and calva also can’t find it’s location when I try to go to definition
(ns main.theme
(:require #?(:cljs [stylefy.core :as s])))
#?(:cljs (defmacro use-style [style] (s/use-style ~style {:class `(->> ~style meta :name)})))
Others probably know better, but perhaps ClojureScript only supports user-defined macros in files ending with .clj suffix?
If that form (:require #?(:cljs [stylefy.core :as s]))
is ever evaluated by Clojure, I bet it might cause problems, since it would expand to (:require)
Everything I found online suggests that is how you properly import from clojurescript libraries
I haven't tried this, but my first guess would be to move the #?(:cljs ...)
so it is around the entire (:require [...])
expression
hi
I'm working on including an existing react component library into a shadow-cljs/reagent project, but whenever I require the component, it gives me a Cannot convert a Symbol value to a string
. Anybody know what that's about?
I figured out some of the mystery. Since these are declared as objects, you have to call (.render Component (clj->js {}))
I'm shooting from the hip here, so may not be giving the best advice.
In Clojure (not ClojureScript) REPL:
user=> (ns foo.bar (:require))
Syntax error macroexpanding clojure.core/ns at (REPL:1:1).
((:require)) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form
Similarly for this:
user=> (ns foo.bar (:require #?(:cljs [a b])))
Syntax error macroexpanding clojure.core/ns at (REPL:1:1).
((:require)) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form
What you tried would probably work fine if there were other namespaces inside the (:require ...)
form that did not have #?(:cljs ...) around them, because then it would turn into something that did not have an empty (:require)
expression
@andy.fingerhut and the import I intended on bringing in would still work?
Not sure. I'd say give it a shot and see what happens 🙂
ask away.
OK! So the advice you gave me worked, but when I import in another file I get an undeclared var problem.
That isn't a question 🙂
It is a statement of fact, with no question.
If your question is "what is wrong with my code?" then I can't see your code, so have no information to go on.
(ns components.nav.nav-component
(:require [components.header.header-component :refer [header-component]]
[main.routing.route-paths :refer [navigation-links]]
[components.nav.nav-item-component :refer [nav-item-component]]
[main.theme :refer-macros [use-style]]))
; (def nav-link-container )
(def article-list-view-style {:width "80%"
:list-style-type "none"})
(def nav-link-container [:ul {:style {:list-style-type "none"}}])
(js/console.log (use-style #'article-list-view-style))
------------------------^-------------------------------------------------------
Use of undeclared Var components.nav.nav-component/use-style
So even though there is require error, the use-style doesn’t seem to get registered or something.
I am not sure what is wrong. I would suggest trying putting the macro definition into a file with .clj suffix, but again, that is a guess, so perhaps a (short) waste of time.
Warnings are better than errors 🙂
This page of documentation about ClojureScript suggests that it should be possible to define macros in a .cljc file: https://clojurescript.org/about/differences#_macros
`The required namespace “utils.macros” is not available, it was required by “components/nav/nav_component.cljs”. “utils/macros.clj” was found on the classpath. Should this be a .cljs file?`
Yeah I looked at that page and didn’t get much from it. It just explained when macros and functions are processed.
It gives several variations of :require
and :require-macros
subexpressions inside of ns
forms that are documented as supported.
I do not know for sure what might be wrong with yours. The only difference I see between it and the examples on that page are that page examples have :as alias
before :refer-macros
, but I do not know if that is needed, or optional.
I have fairly little experience with ClojureScript-specific issues at this point (much more with Clojure), so just because I don't know the answer, I'd guess someone else on this channel with more cljs experience could figure it out quickly.
If your code is in a public Github repository or something similar, you could point people at it when asking for help.
I think it’s more my inexperience. I’ve been trying for quite a while so I might be just too tired to figure it out.
no problem
Are you familiar with #ifdef in C/C++? It is somewhat similar to that.
Basically the entire expression becomes nothing if it is read in by Clojure, if there is no :clj
subexpression, and it becomes nothing if it is read in by ClojureScript, if there is no :cljs
subexpression.
Because (ns foo.bar (:require))
is not legal Clojure syntax
Now you are saying this, I guess what is happening now is that nothing in that file is being evaluated
Again, someone else could say more, but the ClojureScript compiler is written in Clojure, and is involved much more with files containing macros. I would guess Clojure is much more directly involved with macro definition files than .cljs files.
They probably have to be legal for both Clojure and ClojureScript compilers.
Otherwise the #?(:cljs ) could be eliminated and it would still work
If nothing in a file is being evaluated, it shouldn't give you a syntax error
If it gives you an error, something is reading it and trying to interpret its contents.
I wasn't suggestion that you should remove the #?(:cljs ) by the way. But ask yourself this: why do examples you have seen include that? Why did they bother adding it if it was unnecessary?
My guess (not certain knowledge) is that it is necessary, because the Clojure compiler is also evaluating the files defining macros.
If it still gives problems, I would try putting the macro definition in a .clj file to see if it makes a difference, but only if it doesn't work as you have just changed it to.