Clojure
Quick Post – Multiple Shadow-CLJS builds at the same runtime
One of the greatest limitations of ClojureScript is how you can’t have two ClojureScript codebases, running on “development mode”, in the same runtime. In the browser, or in Node.JS, this is not a big problem, but it is one in some other situations – like browser extensions (you might be developing two extensions at the same time), node libraries (again, same case) and… well, editor plug-ins for Pulsar, or VSCode.
That… might not be a problem anymore.
If you use Shadow-CLJS (and you should) then you can just change your target to :npm-module
(or :esm
if you’re in the browser). That will create a lot of files but the important one is cljs_env.js
. What this file does, is bootstrap the Google Closure Compiler and make some assignments for Shadow and for ClojureScript namespaces.
In the beginning of the file, you’ll see this line:
var CLJS_GLOBAL = global; var $CLJS = CLJS_GLOBAL;
Just change it to:
global.some_unique_identifier = {} var CLJS_GLOBAL = global.some_unique_identifier; var $CLJS = CLJS_GLOBAL;
And that’s done.
(more…)