A Clojure tools.deps template for quickly creating a re-frame application scaffold (client only). It only takes you 60 seconds to create your first re-frame app and to start editting it.
Provides a way to pick and choose what "extras" are included into your application. Extras like libraries which do routing, debugging and CSS.
This is a translation of the Leiningen based template from
day8 to use the
seancorfield/clj-new
template mechanism for tools.deps style builds. It does
not have all the options the original had as I did not know how to use them or
translate them to deps.edn style.
The following are not included:
Pull Requests welcome!
Will be adding reitit
The base template includes:
Set up an alias for clj-new
{:aliases
{:new {:extra-deps {seancorfield/clj-new
{:mvn/version "1.0.199"}}
:main-opts ["-m" "clj-new.create"]}}
...}
The easiest way is to use clj-new and this template from Clojars. To create an application with just the base template, use this commandline:
clj -A:new re-frame-template <myname/project-name>
where you might, for example, substitute my-github-name/my-killer-app
for the
<myname/project-name>
bit or, perhaps, my-github-name/an-early-masterpiece
.
By default this will try to write the output to the pathmyname/project-name
.
If you want it to just go to project-name
or some other arbitrary name you can
append at the end -o project-name
or whatever name you want.
Troubleshooting note: for
<project-name>
don't usecljs
. That name will confuse the compiler (long story) and you will later see errors likecljs.core.init is not a function
.
Clone this repo locally and then you can use it this way:
clj -A:new <path-to-re-frame-template repo>::re-frame-template <myname/project-name>
The optional extras (aka profiles) include:
+10x
)+re-frisk
)+re-com
)+re-pressed
)+breaking-point
)To add a profile
to the base template, just append its name (let's use +re-com
as an example):
clj -A:new <path-to-re-frame-template repo>::re-frame-template <myname/project-name> +re-com
Any combination of profiles
can be added at once:
clj -A:new <path-to-re-frame-template repo>::re-frame-template <myname/project-name> +re-com +test +10x
Note: to assist debugging, you'll want to include either
+10x
or+re-frisk
Refer to the shadow-cljs Emacs / CIDER documentation.
The mentioned dir-local.el
file is created by this template.
Retrieve dependencies (can take a while the first time):
yarn install # or npm install
Then run:
shadow-cljs -A dev watch app
Wait a bit, perhaps 20 seconds, keeping an eye out for a sign the compile has finished, then browse to http://localhost:8280.
To see other available shadow-cljs
commands run:
shadow-cljs --help
So, you now have the application running.
Before you start developing, you should tweak two settings within your
browser's devtools
. These are one-time actions (for each browser and laptop you use).
I'll assume Chrome for the purposes of further explanation:
F12
or Ctrl-Shift-i
(actually there's a variety of ways)To use re-frame-10x
for debugging your app:
Ctrl-H
and you should see the re-frame-10x
panel appear on the right side of the windowSometimes achieving Step 1 on a really simple app - one without widgets - can be fiddly,
because the browser itself hogs "input focus" and grabs all the keystrokes (like Ctrl-H
) which don't
then make it through to your app. You may need to be determined and creative with Step 1.
I have every confidence in you.
If you now edit files, like perhaps /src/cljs/<project-name>/views.cljs
, shadow-clj will automatically
recompile your changes and "hot load" them into your running app, without your app needing
to be re-started. The resulting fast, iterative workflow tends to make you very productive, and
is cherished by those lucky enough to experience it.
In project-name.config, there is a variable called debug?
, which defaults to
true in the dev
build, and false in the prod
build.
If, for example, you wrap your println
s with a when
block as shown below,
then you will get logs printed to the browser's console for the dev
build and
not the prod
build.
(when config/debug?
(println "dev mode"))
Install karma and headless chrome
npm install -g karma-cli
And then run your tests
shadow-cljs -A prod compile karma-test
karma start --single-run --reporters junit,dots
To compile clojurescript to javascript:
shadow-cljs -A prod release app
Looking for more re-frame inspiration, templates or example applications? See the external resources docs page.
Build a deployable jar of this template:
$ clojure -A:jar
Install it locally:
$ clojure -A:install
Deploy it to Clojars -- needs CLOJARS_USERNAME
and CLOJARS_PASSWORD
environment variables:
$ clojure -A:deploy
Contributions are welcomed! To add a new profile, this is what I'd recommend:
clj -A:install
clj -A:new <path-to-re-frame-template repo>::re-frame-template <myname/project-name> +<profile-name>
The MIT License (MIT)
clj-new implementation by: Copyright (c) 2020 Robert Berger
Based on the original lein template version by: day8:
The MIT License (MIT)
Copyright © 2015 Matthew Jaoudi
Copyright © 2015 Dylan Paris
Copyright © 2015 Michael Thompson
Copyright © 2015 Markku Rontu
Copyright © 2016 Daniel Compton
Copyright © 2019 Isaac Johnston
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close