• Stars
    star
    2,147
  • Rank 21,492 (Top 0.5 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ClojureScript compilation made easy

npm Clojars Project

shadow-cljs provides everything you need to compile your ClojureScript code with a focus on simplicity and ease of use.

Features

  • Good configuration defaults so you don't have to sweat the details
  • Seamless npm integration
  • Fast builds, reliable caching, ...
  • Supporting various targets :browser, :node-script, :npm-module, :react-native, :chrome-extension, ...
  • Live Reload (CLJS + CSS)
  • CLJS REPL
  • Code splitting (via :modules)

overview-img

Requirements

  • node.js (v6.0.0+, most recent version preferred)
  • npm (comes bundled with node.js) or yarn
  • Java SDK (Version 11+, Latest LTS Version recommended)

Quick Start

Creating your project can be done quickly using the npx create-cljs-project utility. npx is part of npm and lets us run utility scripts quickly without worrying about installing them first. The installer will create a basic project scaffold and install the latest version of shadow-cljs in the project.

$ npx create-cljs-project acme-app
npx: installed 1 in 5.887s
shadow-cljs - creating project: .../acme-app
Creating: .../acme-app/package.json
Creating: .../acme-app/shadow-cljs.edn
Creating: .../acme-app/.gitignore
Creating: .../acme-app/src/main
Creating: .../acme-app/src/test
----
Installing shadow-cljs in project.

npm notice created a lockfile as package-lock.json. You should commit this file.
+ shadow-cljs@<version>
added 88 packages from 103 contributors and audited 636 packages in 6.287s
found 0 vulnerabilities

----
Done.
----

The resulting project has the following structure

.
โ”œโ”€โ”€ node_modules (omitted ...)
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ shadow-cljs.edn
โ””โ”€โ”€ src
    โ”œโ”€โ”€ main
    โ””โ”€โ”€ test

shadow-cljs.edn will be used to configure your CLJS builds and CLJS dependencies. package.json is used by npm to manage JS dependencies.

Everything is ready to go if you just want to start playing with a REPL

$ npx shadow-cljs node-repl
# or
$ npx shadow-cljs browser-repl

When building actual projects we need to configure the build first and create at least one source file.

The default source paths are configured to use src/main as the primary source directory. It is recommended to follow the Java Naming Conventions to organize your CLJS namespaces. It is recommended to start all namespaces with a unique enough prefix (eg. company name, project name) to avoid conflicts with generic names such as app.core. Suppose you were building a Web Frontend for Acme Inc. using acme.frontend.app might be a good starting point as it can easily grow to include acme.backend.* later on.

Using the above example the expected filename for acme.frontend.app is src/main/acme/frontend/app.cljs.

Lets start with a simple example for a browser-based build.

(ns acme.frontend.app)

(defn init []
  (println "Hello World"))

Inside the shadow-cljs.edn :builds section add

{...
 :builds
 {:frontend
  {:target :browser
   :modules {:main {:init-fn acme.frontend.app/init}}
   }}}

This config tells the compiler to call (acme.frontend.app/init) when the generated JS code is loaded. Since no :output-dir is configured the default public/js is used. You can start the development process by running:

$ npx shadow-cljs watch frontend
...
a few moments later ...
...
[:frontend] Build completed. (134 files, 35 compiled, 0 warnings, 5.80s)

The compilation will create the public/js/main.js we configured above (:main becomes main.js in the :output-dir). Since we want to load this in the browser we need to create a HTML file in public/index.html.

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>acme frontend</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="/js/main.js"></script>
  </body>
</html>

We also need a simple HTTP server to serve our HTML since modern Browsers all place a few restrictions on files loaded directly from disk which will lead to issues later. shadow-cljs provides such a server but you can use anything you like at this point. It only matters that the files from the public directory are served properly. To start the built-in web server just adjust the build config from above.

{...
 :dev-http {8080 "public"}
 :builds
 {:frontend
  {:target :browser
   :modules {:main {:init-fn acme.frontend.app/init}}
   }}}

Once the config is saved the server will automatically start and serve the content at http://localhost:8080. There is no need to restart shadow-cljs. When opening the above URL the Browser Console should show "Hello World".

To be continued ...

Documentation

Please refer to the User Manual. (Work in Progress)

Video Courses

Guides

Examples

Libraries

  • flexsurfer/rn-shadow-steroid - React Native with shadow-cljs on steroids
  • re-frame-flow - A graph based visualization tool for re-frame event chains using shadow-cljs
  • ... please let me know if you created something to include here

License

Copyright ยฉ 2022 Thomas Heller

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

shadow-arborist

Exploring a CLJS world without React, see shadow-grove repo instead.
Clojure
198
star
2

shadow-grove

A ClojureScript system to build browser based frontends
Clojure
194
star
3

shadow-experiments

Archived. See shadow-grove.
Clojure
116
star
4

shadow-build

[DEPRECATED] merged into the thheller/shadow-cljs project
Clojure
100
star
5

shadow-css

CSS-in-CLJ(S)
Clojure
80
star
6

reagent-expo

test using reagent with expo/react-native
Clojure
51
star
7

next-cljs

Proof of concept: next + shadow-cljs [unmaintained]
Clojure
50
star
8

shadow

collection of useful CLJS code
Clojure
50
star
9

reagent-react-native

Example App using reagent with react-native via shadow-cljs
Java
47
star
10

gatsby-cljs

Proof of concept: gatsby + shadow-cljs [unmaintained]
CSS
32
star
11

shadow-cljsjs

Clojure
23
star
12

code-splitting-clojurescript

Example App using ClojureScript :modules and shadow-cljs
Clojure
21
star
13

wasm-pack-cljs

quick demo using wasm-pack generated wasm from CLJS
JavaScript
18
star
14

react-router-cljs

example app using react-router with reagent and shadow-cljs
Clojure
15
star
15

shadow-pgsql

PostgreSQL Client for the JVM
Java
15
star
16

fulcro-expo

test using fulcro with expo/react-native
Clojure
15
star
17

js-framework-shadow-grove

Clojure
14
star
18

reagent-pdfjs

Clojure
13
star
19

chrome-ext-v3

Clojure
11
star
20

netlify-cljs

demo frontend+function deployed to netlify
Clojure
10
star
21

shadow-graft

Clojure
10
star
22

reagent-react-integration

JavaScript
9
star
23

electron-cljs

Electron App Example in ClojureScript using shadow-cljs
Clojure
8
star
24

shadow-cljs-ext

Loading the shadow-cljs UI in browser devtools
JavaScript
8
star
25

lambda-cljs

AWS Lambda via shadow-cljs
Clojure
6
star
26

zpipe

Experiment: MsgPack + ZeroMQ == super simple RPC
Ruby
6
star
27

clojure-cli

clojure cli installable via npm
Clojure
5
star
28

shadow-undertow

undertow via clojure
Clojure
5
star
29

cordova-cljs

bare bones example using shadow-cljs with cordova
Clojure
4
star
30

lumifoo

luminus template output ported to shadow-cljs
Clojure
3
star
31

grove-todo

Clojure
3
star
32

cassandra-erl

UNMAINTAINED! hopefully some kind of usable cassandra client, hiding the horrible thrift api.
Erlang
3
star
33

thrift-erl

UNMAINTAINED! extracted from apache/thrift, just the erl bindings
Erlang
3
star
34

cljs-cf-worker

Clojure
2
star
35

cljs-protobuf

Example using protobuf in a CLJS project
JavaScript
2
star
36

regl-example

Clojure
2
star
37

timed-counter

simple Counters in redis
Ruby
2
star
38

gen_http

Erlang Web Framework Experiments
Erlang
1
star
39

shadow-mui-dashboard-test

JavaScript
1
star
40

cljs-issues

JavaScript
1
star
41

zprint-npm

Clojure
1
star
42

shadow-re-frame

Starting point for ClojureScript apps with shadow-cljs, proto-repl, and re-frame.
Clojure
1
star
43

p5-tiledmap-demo

JavaScript
1
star
44

cljs-i18n-api

API proposal for compiler-aided i18n for CLJS (draft)
Clojure
1
star
45

code-splitting-challenge

Clojure
1
star
46

fulcro-questions

some fulcro experiments/questions
HTML
1
star
47

tagged-exchange

RabbitMQ tagged exchange
Erlang
1
star
48

zview

zview - Erlang Template Engine (inspired by erlydtl, Django Templates, Liquid and others.)
Erlang
1
star