or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

build-configuration.mdbuild-targets.mdcli-commands.mdindex.mdprogrammatic-api.md

build-targets.mddocs/

0

# Build Targets

1

2

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.

3

4

## Capabilities

5

6

### Browser Target

7

8

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

9

10

```clojure { .api }

11

{:target :browser

12

:output-dir string ;; Directory for generated JS files

13

:asset-path string ;; Public path for assets

14

:public-dir string ;; Directory for public assets

15

:modules map ;; Module configuration for code splitting

16

:dev map ;; Development-specific options

17

:release map ;; Production-specific options}

18

19

;; Module configuration

20

{module-id {:entries [namespace-symbol] ;; Entry point namespaces

21

:init-fn symbol ;; Initialization function

22

:depends-on #{module-id} ;; Module dependencies

23

:prepend string ;; Code to prepend

24

:append string ;; Code to append

25

:web-workers boolean ;; Enable web worker support}}

26

```

27

28

**Usage Examples:**

29

30

```clojure

31

;; Single-page application

32

{:target :browser

33

:output-dir "public/js"

34

:asset-path "/js"

35

:modules {:main {:init-fn myapp.core/init

36

:preloads [devtools.preload]}}}

37

38

;; Multi-module application with code splitting

39

{:target :browser

40

:output-dir "public/js"

41

:asset-path "/js"

42

:modules {:shared {:entries [myapp.shared]}

43

:main {:init-fn myapp.core/init

44

:depends-on #{:shared}}

45

:admin {:init-fn myapp.admin/init

46

:depends-on #{:shared}}}}

47

48

;; Development and release configurations

49

{:target :browser

50

:output-dir "public/js"

51

:asset-path "/js"

52

:modules {:main {:init-fn myapp.core/init}}

53

:dev {:preloads [devtools.preload]

54

:console-support true

55

:devtools {:http-port 9630

56

:http-root "public"}}

57

:release {:optimize-constants true

58

:module-hash-names true

59

:compress-js true}}

60

```

61

62

### Node Script Target

63

64

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

65

66

```clojure { .api }

67

{:target :node-script

68

:main namespace-symbol ;; Main namespace with -main function

69

:output-to string ;; Output file path

70

:hashbang boolean ;; Include #!/usr/bin/env node

71

:node-modules-dir string ;; Custom node_modules location}

72

```

73

74

**Usage Examples:**

75

76

```clojure

77

;; Basic Node.js script

78

{:target :node-script

79

:main myapp.server/main

80

:output-to "server.js"}

81

82

;; Executable script with hashbang

83

{:target :node-script

84

:main myscript.cli/main

85

:output-to "bin/myscript"

86

:hashbang true}

87

88

;; Script with custom node_modules

89

{:target :node-script

90

:main myapp.worker/main

91

:output-to "worker.js"

92

:node-modules-dir "../shared/node_modules"}

93

```

94

95

### Node Library Target

96

97

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

98

99

```clojure { .api }

100

{:target :node-library

101

:output-to string ;; Output file path

102

:exports map ;; Export configuration

103

:exports-var symbol ;; Variable containing exports map}

104

105

;; Export configuration

106

{:exports {:default symbol ;; Default export function/value

107

:other-export symbol ;; Named exports}}

108

```

109

110

**Usage Examples:**

111

112

```clojure

113

;; Library with named exports

114

{:target :node-library

115

:output-to "lib/mylib.js"

116

:exports {:default mylib.core/api

117

:helper mylib.util/helper-fn

118

:config mylib.config/settings}}

119

120

;; Library using exports variable

121

{:target :node-library

122

:output-to "lib/mylib.js"

123

:exports-var mylib.core/exports}

124

```

125

126

### NPM Module Target

127

128

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

129

130

```clojure { .api }

131

{:target :npm-module

132

:entries [namespace-symbol] ;; Entry point namespaces

133

:output-dir string ;; Output directory

134

:runtime :node ;; Runtime environment}

135

```

136

137

**Usage Examples:**

138

139

```clojure

140

;; NPM publishable module

141

{:target :npm-module

142

:entries [mylib.api mylib.utils]

143

:output-dir "dist"

144

:runtime :node}

145

146

;; Browser-compatible NPM module

147

{:target :npm-module

148

:entries [mylib.browser]

149

:output-dir "dist/browser"

150

:runtime :browser}

151

```

152

153

### React Native Target

154

155

Compiles ClojureScript for React Native applications with Metro bundler integration.

156

157

```clojure { .api }

158

{:target :react-native

159

:init-fn symbol ;; App initialization function

160

:output-dir string ;; Output directory

161

:platform keyword ;; :ios, :android, or :both}

162

```

163

164

**Usage Examples:**

165

166

```clojure

167

;; React Native application

168

{:target :react-native

169

:init-fn myapp.mobile/init

170

:output-dir "target/react-native"}

171

172

;; Platform-specific build

173

{:target :react-native

174

:init-fn myapp.ios/init

175

:output-dir "target/ios"

176

:platform :ios}

177

```

178

179

### Chrome Extension Target

180

181

Compiles ClojureScript for Chrome browser extensions with manifest integration.

182

183

```clojure { .api }

184

{:target :chrome-extension

185

:extension-dir string ;; Extension directory

186

:manifest-file string ;; Manifest.json file path

187

:background map ;; Background script configuration

188

:content-scripts [map] ;; Content script configurations}

189

190

;; Background script configuration

191

{:init-fn symbol ;; Background initialization function

192

:entries [namespace-symbol]} ;; Background entry namespaces

193

194

;; Content script configuration

195

{:matches [string] ;; URL match patterns

196

:init-fn symbol ;; Content script initialization

197

:entries [namespace-symbol]} ;; Content script entry namespaces

198

```

199

200

**Usage Examples:**

201

202

```clojure

203

;; Chrome extension with background and content scripts

204

{:target :chrome-extension

205

:extension-dir "extension"

206

:background {:init-fn myext.background/init

207

:entries [myext.background]}

208

:content-scripts [{:matches ["https://example.com/*"]

209

:init-fn myext.content/init

210

:entries [myext.content]}]}

211

```

212

213

### Electron Target

214

215

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

216

217

```clojure { .api }

218

{:target :electron

219

:output-dir string ;; Output directory

220

:main-config map ;; Main process configuration

221

:renderer-config map ;; Renderer process configuration}

222

223

;; Main process configuration

224

{:init-fn symbol ;; Main process initialization

225

:entries [namespace-symbol]} ;; Main process entry namespaces

226

227

;; Renderer process configuration

228

{:init-fn symbol ;; Renderer initialization

229

:entries [namespace-symbol]} ;; Renderer entry namespaces

230

```

231

232

**Usage Examples:**

233

234

```clojure

235

;; Electron application

236

{:target :electron

237

:output-dir "resources/app"

238

:main-config {:init-fn myapp.electron.main/init

239

:entries [myapp.electron.main]}

240

:renderer-config {:init-fn myapp.electron.renderer/init

241

:entries [myapp.electron.renderer]}}

242

```

243

244

### Node Test Target

245

246

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

247

248

```clojure { .api }

249

{:target :node-test

250

:output-to string ;; Test output file

251

:autorun boolean ;; Automatically run tests

252

:main namespace-symbol ;; Test runner main function

253

:ns-regexp string ;; Namespace pattern for test discovery}

254

```

255

256

**Usage Examples:**

257

258

```clojure

259

;; Basic test configuration

260

{:target :node-test

261

:output-to "target/test.js"

262

:autorun true}

263

264

;; Custom test runner

265

{:target :node-test

266

:output-to "target/test.js"

267

:main myapp.test-runner/main

268

:ns-regexp "myapp.*-test$"}

269

```

270

271

### Karma Test Target

272

273

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

274

275

```clojure { .api }

276

{:target :karma

277

:output-to string ;; Test output file

278

:ns-regexp string ;; Test namespace pattern}

279

```

280

281

**Usage Examples:**

282

283

```clojure

284

;; Karma browser tests

285

{:target :karma

286

:output-to "target/karma-test.js"

287

:ns-regexp "myapp.*-test$"}

288

```

289

290

### Bootstrap Target

291

292

Creates a bootstrap build for self-hosted ClojureScript compilation.

293

294

```clojure { .api }

295

{:target :bootstrap

296

:output-dir string ;; Bootstrap output directory

297

:entries [namespace-symbol] ;; Bootstrap entry namespaces

298

:macros [namespace-symbol] ;; Macro namespaces to include}

299

```

300

301

**Usage Examples:**

302

303

```clojure

304

;; Self-hosted ClojureScript

305

{:target :bootstrap

306

:output-dir "bootstrap"

307

:entries [cljs.js]

308

:macros [cljs.core.specs.alpha]}

309

```

310

311

## Target-Specific Options

312

313

### Development Options

314

315

Configuration options specific to development builds across all targets.

316

317

```clojure { .api }

318

:dev {:preloads [namespace-symbol] ;; Namespaces to preload

319

:console-support boolean ;; Enable console API

320

:devtools map ;; Development tools configuration

321

:reload-strategy keyword ;; :full, :optimized

322

:before-load symbol ;; Function called before reload

323

:after-load symbol ;; Function called after reload

324

:build-notify boolean ;; Desktop build notifications

325

:supervisor boolean ;; Enable build supervisor}

326

```

327

328

### Release Options

329

330

Configuration options for production/release builds.

331

332

```clojure { .api }

333

:release {:optimize-constants boolean ;; Optimize constant values

334

:static-fns boolean ;; Use static function calls

335

:fn-invoke-direct boolean ;; Direct function invocation

336

:module-hash-names boolean ;; Hash-based module names

337

:compress-js boolean ;; Compress JavaScript output

338

:munge-goog-require boolean ;; Munge goog.require calls}

339

```