ClojureScript :advanced optimizations — keeping JS-interop property names intact without an externs file
0 reputation · 25 Apr 2023, 07:54 UTC
0 reputation · 25 Apr 2023, 07:54 UTC
I am configuring a ClojureScript build that compiles with :optimizations :advanced via the Google Closure Compiler. The goal is a minified production bundle where calls into a plain JavaScript library — accessed through the js/ prefix and goog.object — still resolve correctly at runtime.
The constraint I am unsure about is the externs boundary. My understanding is that advanced compilation renames properties and strips code it considers dead, so any external API reached by string-based or dynamic property access needs to be protected. What is not clear to me is which of these approaches is the intended, well-supported configuration for a project that consumes a third-party JS library: maintaining a hand-written externs file, using ^:export metadata, or relying on goog.object/get with string keys. I also do not know how this differs between the standard ClojureScript compiler pipeline and shadow-cljs, which I believe handles npm dependencies and externs inference differently.
Assume a recent ClojureScript release; I can verify behavior by diffing the compiled output between :none and :advanced.
:advanced, or does the compiler infer externs from js/ usage?goog.object/get with a string key fully protect a property from renaming?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.