Skip to content

Create a Klipse compatible js bundle for a Clojurescript library

Yehonathan Sharvit edited this page Sep 4, 2020 · 2 revisions

Problem

I want to use a ClojureScript library called my-lib inside Klipse. But my-lib is not self hosted compatible.

Solution

Compile my-lib as a JavaScript bundle file named <my_lib_bundle>.js and include the Javascript file in the page where you run Klipse.

How to compile?

When we compile my-lib as a JavaScript bundle, we need to omit namespaces that are already contained in Klipse (e.g cljs.core, clojure.set etc...).

The simplest way to generate a bundle from my-lib without the common namespaces with Klipse is to use the modules flag of the ClojureScript compiler.

Here is the process:

  1. Add this file under your src folder and call it klipse_bundle.cljs
  2. Add this build file to your library.
  3. Change the content of the file with the name of your library and the name of the main namespaces of your library.
  4. Run this command clj --main cljs.main --compile-opts build-for-klipse.edn --compile klipse-bundle