CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-shadow-cljs

ClojureScript compiler and JS bundler with comprehensive development tooling

Pending
Overview
Eval results
Files

build-targets.mddocs/

Build Targets

Shadow-CLJS supports multiple build targets for different deployment environments and use cases. Each target type has specific configuration options and generates appropriate output for its intended runtime environment.

Capabilities

Browser Target

Compiles ClojureScript for web browser environments with support for modules, code splitting, and hot reload.

{:target :browser
 :output-dir string                  ;; Directory for generated JS files
 :asset-path string                  ;; Public path for assets
 :public-dir string                  ;; Directory for public assets
 :modules map                        ;; Module configuration for code splitting
 :dev map                           ;; Development-specific options
 :release map                       ;; Production-specific options}

;; Module configuration
{module-id {:entries [namespace-symbol]     ;; Entry point namespaces
            :init-fn symbol                 ;; Initialization function
            :depends-on #{module-id}        ;; Module dependencies
            :prepend string                 ;; Code to prepend
            :append string                  ;; Code to append
            :web-workers boolean           ;; Enable web worker support}}

Usage Examples:

;; Single-page application
{:target :browser
 :output-dir "public/js"
 :asset-path "/js"
 :modules {:main {:init-fn myapp.core/init
                 :preloads [devtools.preload]}}}

;; Multi-module application with code splitting
{:target :browser
 :output-dir "public/js"
 :asset-path "/js"
 :modules {:shared {:entries [myapp.shared]}
           :main {:init-fn myapp.core/init
                  :depends-on #{:shared}}
           :admin {:init-fn myapp.admin/init
                   :depends-on #{:shared}}}}

;; Development and release configurations
{:target :browser
 :output-dir "public/js"
 :asset-path "/js"
 :modules {:main {:init-fn myapp.core/init}}
 :dev {:preloads [devtools.preload]
       :console-support true
       :devtools {:http-port 9630
                  :http-root "public"}}
 :release {:optimize-constants true
           :module-hash-names true
           :compress-js true}}

Node Script Target

Compiles ClojureScript to executable Node.js scripts with optional hashbang support.

{:target :node-script
 :main namespace-symbol              ;; Main namespace with -main function
 :output-to string                   ;; Output file path
 :hashbang boolean                   ;; Include #!/usr/bin/env node
 :node-modules-dir string           ;; Custom node_modules location}

Usage Examples:

;; Basic Node.js script
{:target :node-script
 :main myapp.server/main
 :output-to "server.js"}

;; Executable script with hashbang
{:target :node-script
 :main myscript.cli/main
 :output-to "bin/myscript"
 :hashbang true}

;; Script with custom node_modules
{:target :node-script
 :main myapp.worker/main
 :output-to "worker.js"
 :node-modules-dir "../shared/node_modules"}

Node Library Target

Compiles ClojureScript to Node.js libraries that can be required by other Node.js code.

{:target :node-library
 :output-to string                   ;; Output file path
 :exports map                        ;; Export configuration
 :exports-var symbol                ;; Variable containing exports map}

;; Export configuration
{:exports {:default symbol          ;; Default export function/value
           :other-export symbol     ;; Named exports}}

Usage Examples:

;; Library with named exports
{:target :node-library
 :output-to "lib/mylib.js"
 :exports {:default mylib.core/api
           :helper mylib.util/helper-fn
           :config mylib.config/settings}}

;; Library using exports variable
{:target :node-library
 :output-to "lib/mylib.js"
 :exports-var mylib.core/exports}

NPM Module Target

Compiles ClojureScript to publishable NPM modules with proper package.json integration.

{:target :npm-module
 :entries [namespace-symbol]         ;; Entry point namespaces
 :output-dir string                  ;; Output directory
 :runtime :node                      ;; Runtime environment}

Usage Examples:

;; NPM publishable module
{:target :npm-module
 :entries [mylib.api mylib.utils]
 :output-dir "dist"
 :runtime :node}

;; Browser-compatible NPM module
{:target :npm-module
 :entries [mylib.browser]
 :output-dir "dist/browser"
 :runtime :browser}

React Native Target

Compiles ClojureScript for React Native applications with Metro bundler integration.

{:target :react-native
 :init-fn symbol                     ;; App initialization function
 :output-dir string                  ;; Output directory
 :platform keyword                   ;; :ios, :android, or :both}

Usage Examples:

;; React Native application
{:target :react-native
 :init-fn myapp.mobile/init
 :output-dir "target/react-native"}

;; Platform-specific build
{:target :react-native
 :init-fn myapp.ios/init
 :output-dir "target/ios"
 :platform :ios}

Chrome Extension Target

Compiles ClojureScript for Chrome browser extensions with manifest integration.

{:target :chrome-extension
 :extension-dir string               ;; Extension directory
 :manifest-file string               ;; Manifest.json file path
 :background map                     ;; Background script configuration
 :content-scripts [map]             ;; Content script configurations}

;; Background script configuration
{:init-fn symbol                     ;; Background initialization function
 :entries [namespace-symbol]}        ;; Background entry namespaces

;; Content script configuration  
{:matches [string]                   ;; URL match patterns
 :init-fn symbol                     ;; Content script initialization
 :entries [namespace-symbol]}        ;; Content script entry namespaces

Usage Examples:

;; Chrome extension with background and content scripts
{:target :chrome-extension
 :extension-dir "extension"
 :background {:init-fn myext.background/init
              :entries [myext.background]}
 :content-scripts [{:matches ["https://example.com/*"]
                    :init-fn myext.content/init
                    :entries [myext.content]}]}

Electron Target

Compiles ClojureScript for Electron applications supporting both main and renderer processes.

{:target :electron
 :output-dir string                  ;; Output directory
 :main-config map                    ;; Main process configuration
 :renderer-config map                ;; Renderer process configuration}

;; Main process configuration
{:init-fn symbol                     ;; Main process initialization
 :entries [namespace-symbol]}        ;; Main process entry namespaces

;; Renderer process configuration
{:init-fn symbol                     ;; Renderer initialization
 :entries [namespace-symbol]}        ;; Renderer entry namespaces

Usage Examples:

;; Electron application
{:target :electron
 :output-dir "resources/app"
 :main-config {:init-fn myapp.electron.main/init
               :entries [myapp.electron.main]}
 :renderer-config {:init-fn myapp.electron.renderer/init
                   :entries [myapp.electron.renderer]}}

Node Test Target

Specialized target for running ClojureScript tests in Node.js environment.

{:target :node-test
 :output-to string                   ;; Test output file
 :autorun boolean                    ;; Automatically run tests
 :main namespace-symbol              ;; Test runner main function
 :ns-regexp string                   ;; Namespace pattern for test discovery}

Usage Examples:

;; Basic test configuration
{:target :node-test
 :output-to "target/test.js"
 :autorun true}

;; Custom test runner
{:target :node-test
 :output-to "target/test.js"
 :main myapp.test-runner/main
 :ns-regexp "myapp.*-test$"}

Karma Test Target

Compiles tests for browser-based testing using Karma test runner.

{:target :karma
 :output-to string                   ;; Test output file
 :ns-regexp string                   ;; Test namespace pattern}

Usage Examples:

;; Karma browser tests
{:target :karma
 :output-to "target/karma-test.js"
 :ns-regexp "myapp.*-test$"}

Bootstrap Target

Creates a bootstrap build for self-hosted ClojureScript compilation.

{:target :bootstrap
 :output-dir string                  ;; Bootstrap output directory
 :entries [namespace-symbol]         ;; Bootstrap entry namespaces
 :macros [namespace-symbol]         ;; Macro namespaces to include}

Usage Examples:

;; Self-hosted ClojureScript
{:target :bootstrap
 :output-dir "bootstrap"
 :entries [cljs.js]
 :macros [cljs.core.specs.alpha]}

Target-Specific Options

Development Options

Configuration options specific to development builds across all targets.

:dev {:preloads [namespace-symbol]   ;; Namespaces to preload
      :console-support boolean       ;; Enable console API
      :devtools map                  ;; Development tools configuration
      :reload-strategy keyword       ;; :full, :optimized
      :before-load symbol           ;; Function called before reload
      :after-load symbol            ;; Function called after reload
      :build-notify boolean         ;; Desktop build notifications
      :supervisor boolean           ;; Enable build supervisor}

Release Options

Configuration options for production/release builds.

:release {:optimize-constants boolean    ;; Optimize constant values
          :static-fns boolean           ;; Use static function calls
          :fn-invoke-direct boolean     ;; Direct function invocation
          :module-hash-names boolean    ;; Hash-based module names
          :compress-js boolean          ;; Compress JavaScript output
          :munge-goog-require boolean   ;; Munge goog.require calls}

Install with Tessl CLI

npx tessl i tessl/npm-shadow-cljs

docs

build-configuration.md

build-targets.md

cli-commands.md

index.md

programmatic-api.md

tile.json