Skip to content

Instantly share code, notes, and snippets.

@jmlsf
jmlsf / js-in-cljs.md
Last active January 25, 2024 23:15
Using JavaScript modules in ClojureScript

Using JavaScript Libraries from ClojureScript

Using JavaScript libraries from ClojureScript involves two distinct concerns:

  1. Packaging the code and delivering it to the browser
  2. Making ClojureScript code that accesses JavaScript libraries safe for advanced optimization

Right now, the only single tool that solves these probems reliably, optimally, and with minimal configuration is shadow-cljs, and so that is what I favor. In paricular, shadow-cljs lets you install npm modules using npm or yarn and uses the resulting package.json to bundle external dependencies. Below I describe why, what alternatives there are, and what solutions I disfavor at this time.

Packaging and Delivering Code

@theasp
theasp / gist:92b36733846be7dc0ed78840d3a3515a
Created January 20, 2018 19:26
NGINX Configuration for shadow-cljs
location /shadow-cljs/ {
# Reverse proxy: http://192.168.0.2:9650/
proxy_pass http://192.168.0.2:9650/;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $http_host;
# Allow websockets
proxy_set_header Upgrade $http_upgrade;
{:optimizations :advanced
:output-dir "./target/client/production/"
:cache-analysis true
:output-modules {
{:id :common
:out "./resources/assets/js/common.js"
:entries '#{com.foo.common}}
{:id :landing
:out "./resources/assets/js/landing.js"
:entries '#{com.foo.landing}
(ns async-test.throttle.core
(:require [cljs.core.async :refer [chan close!o sliding-buffer]]
[clojure.string :as string])
(:require-macros
[cljs.core.async.macros :as m :refer [go alts!]]))
(def c (chan (sliding-buffer 1)))
(def loc-div (.getElementById js/document "location"))
(.addEventListener js/window "mousemove"