### Shadow-cljs Configuration: Example Build Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc An example shadow-cljs.edn configuration for a browser build. ```clojure { :dependencies [[reagent "0.8.0-alpha2"]] :source-paths ["src"] :builds {:app {:target :browser :output-dir "public/js" :asset-path "/js" :modules {:main {:entries [my.app]}}}}} ``` -------------------------------- ### Start shadow-cljs Watch and REPL Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc These commands demonstrate how to start the shadow-cljs build watch process for a specific build and then connect to its nREPL server. This allows interactive development with ClojureScript. ```clojure (shadow/watch :the-build) (shadow/repl :the-build) ``` -------------------------------- ### CIDER REPL Session Output Example Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/editor-integration.adoc Example output seen in the CIDER REPL after successfully connecting to a shadow-cljs nREPL server and starting a ClojureScript REPL. ```clojure-repl shadow.user> To quit, type: :cljs/quit [:selected :app] cljs.repl> ``` -------------------------------- ### User Configuration for Dependencies Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Example of user-specific configuration for shadow-cljs, stored in `~/.shadow-cljs/config.edn`. This file allows adding dependencies that apply to all projects and configuring build aliases. ```clojure { :dependencies [[cider/cider-nrepl "0.21.1"]] } ;; this version may be out of date, check whichever is available ``` -------------------------------- ### Shadow-cljs Configuration: Dependencies Example Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc An example of declaring Clojure(Script) dependencies in shadow-cljs.edn. ```clojure { :source-paths ["src"] :dependencies [[reagent "0.9.1"]] :builds ... } ``` -------------------------------- ### Install shadow-cljs with NPM Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Installs shadow-cljs as a development dependency using npm. ```bash $ npm install --save-dev shadow-cljs ``` -------------------------------- ### Example :browser Config with module entries Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc Illustrates a basic :browser configuration in shadow-cljs, focusing on the module setup. It shows how to define the entry points for a specific module, which shadow-cljs uses to build the dependency graph. ```clojure { ... :builds {:app {:target :browser :output-dir "public/js" ... :modules {:main {:entries [my.app]}}}}} ``` -------------------------------- ### Install shadow-cljs with Yarn Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Installs shadow-cljs as a development dependency using Yarn. ```bash $ yarn add --dev shadow-cljs ``` -------------------------------- ### Create Clojure Project Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Creates a new Clojure project with necessary basic files using npx. ```bash $ npx create-cljs-project my-project ``` -------------------------------- ### Install JavaScript Package with npm Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Demonstrates how to install a JavaScript package using npm, which is directly applicable to shadow-cljs projects. ```bash # npm $ npm install the-thing ``` -------------------------------- ### Build HTML Docs with Docker - Bash Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/README.md This command builds the primary HTML documentation file using Docker. It assumes Docker and Make are installed and configured. ```bash make docker-build ``` -------------------------------- ### Node Library Full Example: Runtime Usage Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of consuming the Node.js library built in the full example, demonstrating how to require and call the exported function. ```javascript $ cd out/demo-library $ node > var x = require('./lib'); undefined > x.hello() hello 'hello' ``` -------------------------------- ### shadow-cljs Command Line Examples Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/usage.adoc Demonstrates common shadow-cljs commands for development workflows, including compilation, watching for changes, and connecting to REPLs. ```bash $ shadow-cljs help ``` ```bash # npm $ npx shadow-cljs help # yarn $ yarn shadow-cljs help # manually $ ./node_modules/.bin/shadow-cljs help ``` ```bash # compile a build once and exit $ shadow-cljs compile app # compile and watch $ shadow-cljs watch app # connect to REPL for the build (available while watch is running) $ shadow-cljs cljs-repl app # connect to standalone node repl $ shadow-cljs node-repl ``` ```bash $ shadow-cljs release app ``` ```bash $ shadow-cljs check app $ shadow-cljs release app --debug ``` ```bash $ shadow-cljs server ``` -------------------------------- ### Leiningen REPL Middleware Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures shadow-cljs middleware for Leiningen projects to enable switching between CLJ and CLJS REPLs. Ensure the shadow-cljs REPL server is started manually. ```clojure (defproject my-amazing-project "1.0.0" ... :repl-options {:init-ns shadow.user ;; or any of your choosing :nrepl-middleware [shadow.cljs.devtools.server.nrepl/middleware]}) ...) ``` -------------------------------- ### Start and manage shadow-cljs server mode Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Demonstrates how to run shadow-cljs in server mode for faster command execution. This includes starting the server in the foreground, in the background using start/stop/restart commands, and how other commands leverage the running server. ```bash $ shadow-cljs server # or (if you'd like REPL to control the server process) $ shadow-cljs clj-repl ``` ```bash $ shadow-cljs start $ shadow-cljs stop $ shadow-cljs restart ``` -------------------------------- ### shadow-cljs.edn Project Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html An example of a shadow-cljs.edn configuration file, including source paths, dependencies, and build definitions for a browser target. ```clojure { :dependencies [[reagent "0.8.0-alpha2"]] :source-paths ["src"] :builds {:app {:target :browser :output-dir "public/js" :asset-path "/js" :modules {:main {:entries [my.app]}}}}} ``` -------------------------------- ### Shadow-cljs Configuration: Basic Structure Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Shows the basic structure of the shadow-cljs.edn configuration file, including source paths, dependencies, and builds. ```clojure { :source-paths [...] :dependencies [...] :builds {...}} ``` -------------------------------- ### Example Test Namespace Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc A basic example of a ClojureScript test file using cljs.test. It defines a namespace and a test case that asserts an equality. ```clojure (ns demo.app-test (:require [cljs.test :refer (deftest is)])) (deftest a-failing-test (is (= 1 2))) ``` -------------------------------- ### shadow-cljs npm package installation Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Installs the shadow-cljs npm package, providing a command-line interface for build functionality. This is the recommended way to use shadow-cljs for an optimized development experience. ```bash npm install --save-dev shadow-cljs ``` -------------------------------- ### Basic Browser Target Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html A fundamental configuration example for a browser target in shadow-cljs.edn, specifying dependencies, source paths, and build output details. ```clojure {:dependencies [...] :source-paths [...] :builds {:app {:target :browser :output-dir "public/assets/app/js" :asset-path "/assets/app/js" :modules {:main {:entries [my.app]}}}}} ``` -------------------------------- ### Full Example: Building and consuming a Node library Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-node-library.adoc A complete example demonstrating the build configuration and runtime usage of a Node.js library created with Shadow-cljs. ```clojure (ns demo.lib) (defn hello [] (prn "hello") "hello") ``` ```clojure {... :builds {:library {:target :node-library :output-to "out/demo-library/lib.js" :exports {:hello demo.lib/hello}}}} ``` ```bash $ cd out/demo-library $ node > var x = require('./lib'); undefined > x.hello() hello 'hello' ``` -------------------------------- ### Start Clojure REPL (CLI) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Starts a Clojure REPL from the command line using shadow-cljs. This REPL can be used to control the shadow-cljs process and execute build commands. ```bash $ shadow-cljs clj-repl ``` -------------------------------- ### Install Shadow CLJS via npm Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html This command installs the Shadow CLJS build tool globally using npm, making it available for use across your projects. ```bash npm install -g ഞാൻ shadow-cljs ``` -------------------------------- ### Initialize shadow-cljs Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Initializes a default shadow-cljs.edn configuration file. ```bash $ shadow-cljs init ``` -------------------------------- ### shadow-cljs API Examples Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Demonstrates various functions from the `shadow.cljs.devtools.api` namespace, mapping to common shadow-cljs CLI commands like watch, compile, and REPL connections. ```clojure ;; shadow-cljs watch foo (shadow.cljs.devtools.api/watch :foo) ;; this is identical, due to the provided ns alias (shadow/watch :foo) ;; shadow-cljs watch foo --verbose (shadow/watch :foo {:verbose true}) ;; shadow-cljs compile foo (shadow/compile :foo) ;; shadow-cljs release foo (shadow/release :foo) ;; shadow-cljs browser-repl (shadow/browser-repl) ;; shadow-cljs node-repl (shadow/node-repl) ;; shadow-cljs cljs-repl foo (shadow/repl :foo) ;; Once you are in a CLJS REPL you can use :repl/quit ;; or :cljs/quit ;; to drop back down to CLJ. ``` -------------------------------- ### Bash Command Example Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Demonstrates a typical command-line interaction with Bash, including comments and prompts. Used to illustrate commands and their expected output. ```bash # A comment. This command lists files: $ ls -l shadow-cljs.edn project.clj ... ``` -------------------------------- ### Start and Compile with Embedded shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Demonstrates how to start the shadow-cljs server and initiate a compilation from an embedded Clojure REPL using lein repl. It requires loading the shadow.cljs.devtools.server and shadow.cljs.devtools.api namespaces. ```clojure user=> (require '[shadow.cljs.devtools.server :as server]) nil user=> (server/start!) ... :shadow.cljs.devtools.server/started user=> (require '[shadow.cljs.devtools.api :as shadow]) nil user=> (shadow/compile :foo) ... ``` -------------------------------- ### Node Library Full Example: Build Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Full build configuration for a Node.js library, specifying the target, output file, and named exports. ```clojure (ns demo.lib) (defn hello [] (prn "hello") "hello") {... :builds {:library {:target :node-library :output-to "out/demo-library/lib.js" :exports {:hello demo.lib/hello}}}} ``` -------------------------------- ### Atom Proto REPL setup for ClojureScript Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Provides instructions for setting up the Proto REPL package in Atom for ClojureScript development. This includes creating a `user.clj` file with a `reset` function, adding dependencies, configuring nREPL port, and evaluating specific commands to connect and interact with shadow-cljs builds. ```clojure (ns user) (defn reset []) ``` -------------------------------- ### Start Clojure REPL (Embedded) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Starts a Clojure REPL from the command line, which can then be used to interact with the shadow-cljs process programmatically. ```bash $ shadow-cljs clj-repl ... shadow-cljs - REPL - see (help), :repl/quit to exit [1:0]~shadow.user=> ``` -------------------------------- ### Example Build Hook Implementation Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/build-config.adoc Provides an example implementation of a build hook function named `hook` within the `my.util` namespace, tagged with `{:shadow.build/stage :flush}` to specify its execution stage. ```clojure (ns my.util) (defn hook {:shadow.build/stage :flush} [build-state & args] (prn [:hello-world args]) build-state) ``` -------------------------------- ### Configure Development HTTP Server Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Defines the root directory for serving requests and specifies a custom handler for requests that cannot be found locally. Paths starting with 'classpath:' serve from the classpath. ```clojure {... :dev-http {8080 {:root "public" :handler my.app/handler}}} ``` -------------------------------- ### Example bash command for Idea integration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc Illustrates the bash command executed when the :open-file-command is configured for Idea. It shows how project path, line number, and file path are substituted. ```bash $ idea /path/to/project-root --line 3 /path/to/project-root/src/main/demo/foo.cljs ``` -------------------------------- ### Bash Command Prompt Convention Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Illustrates the convention of using a bash prompt '$' to indicate commands and '#' for comments in command-line examples. This helps differentiate commands from their expected output. ```bash # Example of a bash command $ echo "Hello, Shadow CLJS!" ``` -------------------------------- ### Shadow-cljs SSL Keystore Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures SSL for shadow-cljs HTTP servers using a Java Keystore. The default configuration allows using existing keystores with minimal setup. ```clojure {... :ssl {:keystore "ssl/keystore.jks" :password "shadow-cljs"} ...} ``` -------------------------------- ### Running Shadow-cljs Tests with Karma Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Command-line instructions to compile shadow-cljs code for the 'ci' build and then start the Karma test runner in single-run mode. ```bash $ shadow-cljs compile ci $ karma start --single-run ``` -------------------------------- ### Configure JavaScript Dependencies (npm) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Specifies JavaScript dependencies for a Shadow CLJS project. This example includes 'react' and 'react-dom' as npm dependencies, typically managed via `npm install`. ```clojure {:dependencies {:npm {:react "17.0.1" :react-dom "17.0.1"}}} ``` -------------------------------- ### Shadow-cljs Configuration: Dependencies Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of specifying library dependencies in the shadow-cljs configuration file (EDN format). ```clojure { :dependencies [[lib "1.0"]] } ``` -------------------------------- ### Sample Output Manifest (EDN) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example structure of the `manifest.edn` file generated by shadow-cljs. It lists module details, including the `output-name` which contains the hashed filename. ```edn [{:module-id :common, :name :common, :output-name "common.15D142F7841E2838B46283EA558634EE.js", :entries [...], :depends-on #{}, :sources [...]} {:module-id :page-a, :name :page-a, :output-name "page-a.D8844E305644135CBD5CBCF7E359168A.js", :entries [...], :depends-on #{:common}, :sources [...]} ...] ``` -------------------------------- ### Browser Test Configuration (shadow-cljs) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Configuration example for running tests in a browser using shadow-cljs. It sets up HTTP serving for test files and defines the test build target. ```clojure {... ;; tests are served via http://localhost:8021 :dev-http {8021 "out/test"} :builds {:test {:target :browser-test :test-dir "out/test"}}} ``` -------------------------------- ### Start Browser REPL Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Starts a blank ClojureScript REPL and opens an associated browser window for code execution. Functionality is identical to the node-repl, but code runs in the browser. Closing the browser window stops the REPL. ```bash $ shadow-cljs browser-repl ``` -------------------------------- ### Start shadow-cljs Server (Embedded) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Starts the shadow-cljs development server from within an embedded Clojure REPL. This requires the shadow-cljs artifact to be on the classpath. ```clojure user=> (require '[shadow.cljs.devtools.server :as server]) nil user=> (server/start!) ... :shadow.cljs.devtools.server/started ``` -------------------------------- ### Example Build Config for :esm Target Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-esm.adoc This configuration demonstrates how to set up a build for the :esm target in shadow-cljs. It specifies the output directory and defines a module 'demo' with a specific export 'hello' from 'demo.lib'. ```clojure { :source-paths ["src/main"] :dev-http {8000 "public"} :builds {:app {:target :esm :output-dir "public/js" :modules {:demo {:exports {hello demo.lib/hello}}}}}} ``` -------------------------------- ### Configuring Build Aliases in User Config Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc This example shows how to use `:deps-aliases` in `~/.shadow-cljs/config.edn` to activate additional aliases when using `deps.edn`. This allows combining project-specific aliases with global ones. ```clojure ;; shadow-cljs.edn in project {:deps {:aliases [:cljs]}} ;; ~/.shadow-cljs/config.edn {:deps-aliases [:cider]} ``` -------------------------------- ### Shadow-cljs Configuration: Nested Build Options Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of a nested configuration structure in shadow-cljs, showing how build-specific options are defined. ```clojure { ... :builds {:build-id {... :output-dir "resources/public/js" }} } ``` -------------------------------- ### Example bash command for Emacsclient integration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc Demonstrates the bash command executed for emacsclient integration. It shows how the file path and line/column information are passed. ```bash $ emacsclient -n +3:1 /path/to/project-root/src/main/demo/foo.cljs ``` -------------------------------- ### Shadow-cljs Configuration: Source Paths Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of configuring source paths in shadow-cljs, indicating directories where Clojure(Script) source files are located. ```clojure { ... :source-paths ["src"] ... } ``` -------------------------------- ### Node.js HTTP Server with Hot Code Reload Hooks Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Provides an example of a Node.js HTTP server implemented in ClojureScript, demonstrating how to integrate hot code reload. It includes `start` and `stop` functions that are registered as callbacks to manage the server lifecycle during reloads. ```clojurescript (ns demo.script (:require ["http" :as http])) (defn request-handler [req res] (.end res "foo")) ; a place to hang onto the server so we can stop/start it (defonce server-ref (volatile! nil)) (defn main [& args] (js/console.log "starting server") (let [server (http/createServer #(request-handler %1 %2))] (.listen server 3000 (fn [err] (if err (js/console.error "server start failed") (js/console.info "http server running")) )) (vreset! server-ref server))) (defn start "Hook to start. Also used as a hook for hot code reload." [] (js/console.warn "start called") (main)) (defn stop "Hot code reload hook to shut down resources so hot code reload can work" [done] (js/console.warn "stop called") (when-some [srv @server-ref] (.close srv (fn [err] (js/console.log "stop completed" err) (done))))) (js/console.log "__filename" js/__filename) ``` -------------------------------- ### Start Shadow-CLJS Watch Mode Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/editor-integration.adoc Initiates the Shadow-CLJS build process in watch mode for a specified build ID. This command keeps the build running and recompiles code as changes are detected. It requires Node.js and npm/npx to be installed. ```sh npx shadow-cljs watch frontend ``` -------------------------------- ### Shadow-cljs Configuration: Nested Option Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Demonstrates a nested configuration option within the builds section. ```clojure {... :builds {:build-id {... :output-dir "resources/public/js"}}} ``` -------------------------------- ### Proto REPL setup for shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/editor-integration.adoc Creates a `user.clj` file with a `reset` function, required by Proto REPL for ClojureScript development. ```clojure (ns user) (defn reset []) ``` -------------------------------- ### Launch ClojureScript REPL with CIDER Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/editor-integration.adoc Command to execute within Emacs to start a shadow-cljs ClojureScript REPL session using CIDER. ```emacs-lisp M-x cider-jack-in-cljs ``` -------------------------------- ### Install shadow-cljs via npm or Yarn Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Installs shadow-cljs as a development dependency in your project using either npm or Yarn package managers. ```bash $ npm install --save-dev shadow-cljs ``` ```bash $ yarn add --dev shadow-cljs ``` -------------------------------- ### Shadow-cljs Configuration: Dependencies Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures project dependencies using Clojure's EDN map format. ```clojure {:dependencies [[lib "1.0"]]} ``` -------------------------------- ### Start Watch with Server Requirement via Metadata Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/usage.adoc Ensure that a function executed via `clj-run` requires a full shadow-cljs server instance. This is necessary for tasks like starting a `watch` build, which keeps the JVM process alive. ```clojure (ns demo.run (:require [shadow.cljs.devtools.api :as shadow])) ;; this fails because a full server instance is missing (defn foo [& args] (shadow/watch :my-build)) ;; this metadata will ensure that the server is started so watch works (defn foo {:shadow/requires-server true} [& args] (shadow/watch :my-build)) ``` -------------------------------- ### Configure Source Paths Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Defines the source code directories for a Shadow CLJS build. This example specifies 'src/cljs' and 'src/cljs-app' as the locations for ClojureScript code. ```clojure {:source-paths ["src/cljs" "src/cljs-app"]} ``` -------------------------------- ### Running Node.js tests with shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html This section provides command-line examples for compiling and running tests using shadow-cljs. It shows how to compile a build and then execute the generated test runner manually with Node.js, or combine compilation and execution. ```bash $ shadow-cljs compile test # or $ shadow-cljs release test # run tests manually, :autorun will do this automatically $ node out/node-tests.js # compile & test combined $ shadow-cljs compile test && node out/node-tests.js ``` -------------------------------- ### Clojure: Configure modules with dependencies Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc An example of the shadow-cljs build configuration for the `:app` target, demonstrating how to define multiple modules (`:main`, `:extra`) with their respective entry points and specifying dependencies between them. ```clojure {... :builds {:app {:target :browser ... :output-dir "public/js" :asset-path "/js" :modules {:main {:entries [my.app]} :extra {:entries [my.app.extra] :depends-on #{:main}}}}}} ``` -------------------------------- ### Shadow-cljs CLI REPL Command Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl-troubleshoot.adoc This command initiates a REPL session using the shadow-cljs command-line interface for a specific build (e.g., 'app'). It connects to the shadow-cljs server, enabling interactive code evaluation. ```bash shadow-cljs cljs-repl app ``` -------------------------------- ### Advanced HTTP Server Configuration (Clojure) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Configures an HTTP server with a custom handler and root directory. This example serves files from 'public' and uses 'my.app/handler' for requests that are not found locally. ```clojure {... :dev-http {8080 {:root "public" :handler my.app/handler}}} ``` -------------------------------- ### Start Node REPL Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Starts a blank ClojureScript REPL connected to a managed Node.js process. Exiting this REPL will also kill the Node process. It does not support automatic rebuilding or hot-reloading as it's not connected to a build. ```bash $ shadow-cljs node-repl ``` -------------------------------- ### Example Shadow-cljs Build Hook Function Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html An example Clojure function designed to be used as a shadow-cljs build hook. It accepts build state and arguments, and must return the modified build state. Includes metadata to specify execution stages. ```clojure (ns my.util) (defn hook {:shadow.build/stage :flush} [build-state & args] (prn [:hello-world args]) build-state) ``` -------------------------------- ### List Dependencies with tools.deps (shadow-cljs) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/failed-to-load.adoc Lists all active dependencies for a given set of aliases when using shadow-cljs with the `deps.edn` tool. This helps identify potential version conflicts. ```bash $ clj -A:dev:cljs -Stree ``` -------------------------------- ### Run shadow-cljs commands using npx or Yarn Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Demonstrates how to execute shadow-cljs commands without a global installation, using `npx` for npm projects or `yarn` for Yarn projects. This allows for project-specific shadow-cljs versions. ```bash # npm $ npx shadow-cljs help ``` ```bash # yarn $ yarn shadow-cljs help ``` ```bash # manually $ ./node_modules/.bin/shadow-cljs help ``` -------------------------------- ### Basic HTTP Server (Clojure) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Configures a basic HTTP server to serve static files from the 'public' directory on port 8000. This is a common setup for development environments. ```clojure {... :dev-http {8000 "public"} :builds {...}} ``` -------------------------------- ### Shadow-cljs Configuration: Multiple Source Paths Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures the project to use multiple source paths for organizing code. ```clojure { :source-paths ["src/main" "src/test"] ... } ``` -------------------------------- ### Install Missing JavaScript Dependency Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc This command installs a missing JavaScript dependency required by a ClojureScript library. This is often necessary because ClojureScript libraries may not yet declare their npm dependencies. For 'react', you typically need 'react', 'react-dom', and 'create-react-class'. ```bash The required JS dependency "react" is not available, it was required by ... npm install react ``` ```bash npm install react react-dom create-react-class ``` -------------------------------- ### Shadow-cljs Development HTTP Server Basic Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Sets up a basic development HTTP server to serve static files from the 'public' directory on port 8000. These servers are for static file serving and do not handle live-reload or REPL logic. ```clojure { :dev-http {8000 "public"} :builds {...} } ``` -------------------------------- ### Configure Socket REPL Server Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Configures Shadow CLJS to start a Socket REPL server, enabling connections from various Clojure IDEs and tools that support this protocol. ```clojure {:socket-repl {:port 9696}} ``` -------------------------------- ### Using shadow.loader API for Dynamic Module Loading Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Provides examples of using the `shadow.loader` namespace for runtime module loading. It demonstrates loading a single module, loading multiple modules, and using callbacks. It also shows how to check if a module is loaded. ```clojure (ns my.app (:require [shadow.loader :as loader])) (defn fn-to-call-on-load [] (js/console.log "extra loaded")) (defn fn-to-call-on-error [] (js/console.log "extra load failed")) ;; load returns a goog.async.Deferred, and can be used like a promise (-> (loader/load "extra") (.then fn-to-call-on-load fn-to-call-on-error)) ;; must be a JS array, also returns goog.async.Deferred (loader/load-many #js ["foo" "bar"]) (loader/with-module "extra" fn-to-call-on-load) ;; You can check if a module is loaded using `(loaded? "module-name")`. ``` -------------------------------- ### Shadow-cljs Configuration: Source Paths Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures the JVM classpath for finding Clojure(Script) source files. ```clojure {... :source-paths ["src"] ...} ``` -------------------------------- ### Evaluate ClojureScript in CIDER Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of evaluating ClojureScript code within an Emacs/CIDER REPL connected to shadow-cljs, demonstrating interaction with browser JavaScript APIs. ```clojure (js/alert "Jurassic Park!") ``` -------------------------------- ### shadow-cljs Build Configuration with Dev/Release Overrides Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/release.adoc This example shows a shadow-cljs.edn configuration file. It defines a build for a browser target with separate configurations for development (`:dev`) and release (`:release`) modes, including specific compiler options for each. ```clojure { :source-paths ["src"] :dependencies [] :builds {:app {:target :browser :output-dir "public/js" :asset-path "/js" :modules {:base {:entries [my.app.core]}} ;; Here is some dev-specific config :dev {:compiler-options {:devcards true}} ;; Here is some production config :release {:compiler-options {:optimizations :simple}}}}} } ``` -------------------------------- ### Shadow-cljs Configuration for npm-module Target Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-npm-module.adoc Example `shadow-cljs.edn` configuration for the `:npm-module` target. Specifies the output directory and the entry namespace for compilation. ```edn { ... :builds {:code {:target :npm-module :output-dir "out" :entries [demo.foo]}}} ``` -------------------------------- ### Running Karma Tests with Shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-karma.adoc Commands to compile shadow-cljs for Karma and start the Karma test runner in a single-run mode for CI execution. ```bash $ shadow-cljs compile ci $ karma start --single-run 12 01 2018 01:19:24.222:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/ 12 01 2018 01:19:24.224:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency 12 01 2018 01:19:24.231:INFO [launcher]: Starting browser ChromeHeadless 12 01 2018 01:19:24.478:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Connected on socket TcfrjxVKmx7xN6enAAAA with id 85554456 LOG: 'Testing boo.sample-spec' HeadlessChrome 0.0.0 (Mac OS X 10.12.6): Executed 1 of 1 SUCCESS (0.007 secs / 0.002 secs) ``` -------------------------------- ### List Dependencies with Leiningen (shadow-cljs) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/failed-to-load.adoc Lists all dependencies for a Leiningen project, optionally including a specific profile configured for shadow-cljs. This is useful for diagnosing dependency conflicts. ```bash # no profile $ lein deps :tree ``` ```bash # with profile $ lein with-profile +cljs deps :tree ``` -------------------------------- ### Run Shadow CLJS Server Mode Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Starts Shadow CLJS in server mode, typically used for development workflows. This command is often executed from the project's root directory. ```bash shadow-cljs watch app ``` -------------------------------- ### Expo Configuration for React Native Entry Point Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of `app.json` configuration for Expo projects when using shadow-cljs. It specifies the `entryPoint` to point to the compiled shadow-cljs output, typically `./app/index.js`. ```json { "expo": { "name": "hello-world", "slug": "reagent-expo", ... "entryPoint":"./app/index.js", ... } } ``` -------------------------------- ### Conditional Build Configuration (Dev vs. Release) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example of specifying different compiler options for development and release builds within the shadow-cljs configuration file. ```clojure { :source-paths ["src"] :dependencies [] :builds { :app {:target :browser :output-dir "public/js" :asset-path "/js" :modules {:base {:entries [my.app.core]}} ;; Here is some dev-specific config :dev {:compiler-options {:devcards true}} ;; Here is some production config :release {:compiler-options {:optimizations :simple}}} }} ``` -------------------------------- ### Custom ClojureScript Runner Namespace for Browser Tests Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser-test.adoc An example of a custom ClojureScript namespace that can be used as a test runner. It defines `init`, `start`, and `stop` functions to manage test execution and display. ```clojure (ns tests.client-test-main {:dev/always true} (:require [shadow.test :as st] [shadow.test.env :as env] [cljs-test-display.core :as ctd] [shadow.dom :as dom])) (defn start [] (-> (env/get-test-data) (env/reset-test-data!)) (st/run-all-tests (ctd/init! "test-root"))) (defn stop [done] ; tests can be async. You must call done so that the runner knows you actually finished (done)) (defn ^:export init [] (dom/append [:div#test-root]) (start)) ``` -------------------------------- ### Executing Shadow-cljs Watch via clj Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/usage.adoc A command example demonstrating how to run the shadow-cljs watch command using the `clj` utility with a configured alias. ```bash clj -M:shadow-cljs watch app ``` -------------------------------- ### Shadow-cljs Build Configuration for Browser Tests Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser-test.adoc Example shadow-cljs build configuration to set up a :browser-test target. It specifies the output directory for test files and enables serving tests via HTTP. ```clojure {... ;; tests are served via http://localhost:8021 :dev-http {8021 "out/test"} :builds {:test {:target :browser-test :test-dir "out/test"}}} ``` -------------------------------- ### Sample Leiningen Project Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/usage.adoc A sample `project.clj` file demonstrating how to configure dependencies and profiles for shadow-cljs integration. It includes setting up a `:cljs` profile with necessary artifacts. ```clojure (defproject my-awesome-project ... :profiles {:cljs {:source-paths ["src/cljs"] :dependencies [[thheller/shadow-cljs "..."] [reagent "0.8.1"]]}}) ``` -------------------------------- ### Connect to Browser REPL (ClojureScript REPL) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Connects to a browser-based ClojureScript REPL after a watch process has been started. This allows interaction with the browser runtime. ```clojure [2:0]~shadow.user=> (shadow/repl :browser) [2:1]~cljs.user=> ``` -------------------------------- ### Minimal :browser Config with :init-fn Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc Example of a minimal :browser configuration in shadow-cljs, demonstrating the use of the :init-fn option within a module. This function is executed when the module is initially loaded. ```clojure { ... :builds {:app {:target :browser :output-dir "public/js" ... :modules {:main {:init-fn my.app/init}}}}} ``` -------------------------------- ### tools.deps / deps.edn Integration for Shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/usage.adoc Configuration examples for integrating shadow-cljs with tools.deps. This involves setting `:deps true` in `shadow-cljs.edn` and including the shadow-cljs artifact in `deps.edn`. ```clojure {:deps true :builds ...} ``` ```clojure {:paths [...] :deps {thheller/shadow-cljs {:mvn/version }}} ``` ```clojure {:deps {:aliases [:cljs]} :builds ...} ``` ```clojure {:paths [...] :deps {...} :aliases {:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version }}}}} ``` -------------------------------- ### Importing PKCS12 Keystore to JKS Format Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Converts a PKCS12 keystore file (e.g., localhost.pfx) into the JKS format required by Java using the keytool command. Ensure the certificate has a SAN for 'localhost' for Chrome trust. ```bash $ keytool -importkeystore -destkeystore keystore.jks -srcstoretype PKCS12 -srckeystore localhost.pfx ``` -------------------------------- ### Node.js HTTP Server with Hot Code Reload Hooks Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-node-script.adoc An example of a Node.js HTTP server written in ClojureScript, demonstrating the use of `start` and `stop` functions for hot code reload. It includes a basic request handler and manages the server instance using `volatile!`, with `stop` ensuring the server is closed before code reloads. ```clojurescript (ns demo.script (:require ["http" :as http])) (defn request-handler [req res] (.end res "foo")) ; a place to hang onto the server so we can stop/start it (defonce server-ref (volatile! nil)) (defn main [& args] (js/console.log "starting server") (let [server (http/createServer #(request-handler %1 %2))] (.listen server 3000 (fn [err] (if err (js/console.error "server start failed") (js/console.info "http server running")) )) (vreset! server-ref server))) (defn start "Hook to start. Also used as a hook for hot code reload." [] (js/console.warn "start called") (main)) (defn stop "Hot code reload hook to shut down resources so hot code reload can work" [done] (js/console.warn "stop called") (when-some [srv @server-ref] (.close srv (fn [err] (js/console.log "stop completed" err) (done))))) (js/console.log "__filename" js/__filename) ``` -------------------------------- ### Shadow-cljs Development HTTP Server Multiple Roots Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures a development HTTP server to serve static files from multiple directories and classpath locations. Files are served in the order specified in the list. ```clojure :dev-http {8000 ["a" "b" "classpath:c"]} ``` -------------------------------- ### Leiningen Integration for Shadow-cljs Configuration Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/usage.adoc Configuration examples for integrating shadow-cljs with Leiningen. This involves setting a `:lein` entry in `shadow-cljs.edn` to use Leiningen for managing dependencies and source paths via `project.clj`. ```clojure { :lein true ; :source-paths and :dependencies are now ignored in this file ; configure them via project.clj :builds { ... } } ``` ```clojure { :lein {:profile "+cljs"} :builds {...} } ``` -------------------------------- ### Install Missing JS Dependencies with npm Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html When shadow-cljs reports a missing JS dependency, you need to install the corresponding npm package. For 'react', this typically involves installing 'react', 'react-dom', and 'create-react-class'. ```bash npm install react react-dom create-react-class ``` -------------------------------- ### JSX Component Example in Shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/js-deps.adoc Provides an example of a React component written in JSX. This component is intended to be pre-processed by Babel before being used within a shadow-cljs project. The example defines a simple functional component `myComponent` that renders an `

` tag. ```jsx import React from "react"; function myComponent() { return

JSX!

; } export { myComponent }; ``` -------------------------------- ### Watch and Compile Build (ClojureScript REPL) Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/repl.adoc Starts a shadow-cljs watch process for a specified build ID from within a ClojureScript REPL. It then compiles the project and indicates when the build is complete. ```clojure [2:0]~shadow.user=> (shadow/watch :browser) [:browser] Configuring build. [:browser] Compiling ... [:browser] Build completed. (341 files, 1 compiled, 0 warnings, 3,19s) :watching ``` -------------------------------- ### Install JavaScript Package with npm Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Command to install a JavaScript package using npm, which shadow-cljs fully integrates with for dependency management. ```bash $ npm install the-thing ``` -------------------------------- ### Clojure: Configure Multiple Shadow-cljs Modules Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc Configuration example for defining multiple modules in shadow-cljs, specifying entries and dependencies between them. This allows for better code splitting and organization. ```clojure {... :output-dir "public/js" :modules {:shared {:entries [my.app.common]} :home {:entries [my.app.home] :depends-on #{:shared}} :login {:entries [my.app.login] :depends-on #{:shared}} :protected {:entries [my.app.protected] :depends-on #{:shared}}} ``` -------------------------------- ### Shadow-cljs Development HTTP Server Classpath Serving Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc Configures a development HTTP server to serve static files from the 'classpath:public' directory. This allows serving files included in JARs or other classpath resources. ```clojure :dev-http {8000 "classpath:public"} ``` -------------------------------- ### Manual Externs Configuration in shadow-cljs Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/release.adoc Provides an example of configuring manual externs in shadow-cljs by specifying a list of `.js` files in the `:externs` compiler option. These files are searched relative to the project root and then the classpath. ```clojure { ... :builds {:app {:target :browser ... :compiler-options {:externs ["path/to/externs.js" ...]}}} } ``` -------------------------------- ### Clojure Build Hook Example Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/build-config.adoc Defines a Clojure build hook that executes after the ':flush' stage. The hook receives 'build-state' and must return it. Metadata specifies which build stages trigger the hook. ```clojure ;; Example usage: ;; (my.util/hook build-state 1 2 3) ;; Hook definition with metadata: ^{:shadow.build/stages #{:configure :flush}} ; Or :flush (defn my-hook [build-state] ;; Do something useful with build-state build-state) ``` -------------------------------- ### Node Library Example: Single Default Export Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Example ClojureScript code for a single default export. The 'f' symbol is exported, which can be a function or a JavaScript object. ```clojure (ns demo.ns) (defn f [...] ...) ;; OR (def f #js {:foo ...}) ``` -------------------------------- ### Setting Up Preloads for Development Tools Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/build-config.adoc Demonstrates how to define preloads for development tools, such as injecting namespaces like `fulcro.inspect.preload` into the build. ```edn {... :builds {:app {... :devtools {:preloads [fulcro.inspect.preload] ... }}} } ``` -------------------------------- ### Configure shadow-cljs nREPL Server Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.adoc This Clojure code snippet demonstrates how to configure the nREPL server within `shadow-cljs.edn`. You can specify the port, add middleware, disable cider-nrepl integration, and set the initial namespace. ```clojure { ... :nrepl {:port 9000 :middleware []} ; optional list of namespace-qualified symbols ... } ``` ```clojure { ... :nrepl {:init-ns my.repl} ... } ``` ```clojure { ... :nrepl false ...} ``` -------------------------------- ### Clojure: Configure Shadow-cljs for Built-in Loader Support Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/target-browser.adoc Configuration example for enabling shadow-cljs's built-in loader support by setting `:module-loader true`. This allows for runtime on-demand module loading. ```clojure {... :builds {:app {:target :browser ... :module-loader true :modules {:main {:entries [my.app]} :extra {:entries [my.app.extra] :depends-on #{:main}}}}}} ``` -------------------------------- ### Connect to Build-specific REPL via CLI Source: https://github.com/shadow-cljs/shadow-cljs.github.io/blob/master/docs/UsersGuide.html Connects to a REPL for a specific shadow-cljs build after starting a 'watch' process. Requires a running watch for the build and the corresponding JavaScript runtime to be accessible (e.g., browser open or Node process running). ```bash $ shadow-cljs watch build-id ... # different terminal $ shadow-cljs cljs-repl build-id ```