hey all i'm building an esm and require it in a different project when i have an error in the esm code (compiled) i get generated js that i can't figure out the problem can i have a setup where errors in the esm will display in cljs code in the browser?
define "require it in a different project"? usually you should have source maps, but if by "require" you mean build with another tools they might get lost by that tool
project:
import { appJsonToReactElement } from "/home/itai/dev/ui-framework/dist/app-runner.js";
the project is using vite to build itself
lib:
{:target :esm
:js-options {:js-provider :import}
:output-dir "dist"
:compiler-options {:source-map true
:source-map-include-sources-content true}
:modules {:app-runner {:exports {appJsonToReactElement ui-framework.tree.dynamic-runner/appJsonToReactElement}}}
}ok, so you need to setup vite to include the source maps. no clue how you'd do that though.
ok ill look into that, thank you
Hi, is it possible to keep a .js file from being minified in a release build?
Right now, I temporarily require a .js file in cljs and it works perfectly in :dev build. But in the release build, the json data (e.g. {name, options}) posted to an endpoint is not right as the variable names have been changed.
Any advice? thanks!
Is adding externs the right answer? https://cljs.github.io/api/compiler-options/externs
> I temporarily require a .js file in cljs
what does this mean? how do you temporarily require a file?
yes, externs will probably prevent the renaming, but that'll be a bit cumbersome
Oh, I meant at the moment by that, because I will translate it to cljs at some point.
The good news is this is a small js file, so it should be ok.
if you write the file as commonjs, meaning using exports.foo instead of export foo you by bypass this step entirely
commonjs does not go through :advanced and thus doesn't need externs
Okay I will try it, thanks!
exports.foo doesn't work for me unfortunately, don't know why. And I couldn't find helpful docs about how to write an externs js file properly, at last I tries this trick https://ericnormand.me/article/clojurescript-externs and it worked (simply use the JavaScript library as its own externs file)
OK, just got the commonjs way work.
There is a default export in ESM js like export default new Foo(); , and the require form for it is ["./foo.js$default" :as foo]
But for commonjs, the export statement is exports.client = new Foo(); , so the require form should be slightly adapted: ["./foo.js" :as foo]``.
Maybe I should write a more detailed post.
BTW, regarding "commonjs does not go through :advanced and thus doesn't need externs", this is a feature of shadow-cljs, right?
yes, this entire way of directly using .js files is shadow-cljs only