-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
possibility to output a non temporary js file #166
Comments
This "should" be as easy as creating a new block/adding a filename to the context of the current nbJs block. As for the API, something like this maybe? nbJsFromCodeStatic("assets/file.js", captureVar1, captureVar2):
code here |
What if instead we target an api where we just add at the top: nbJsStatic("mylib") With that config the Js collected at the end is compiled to a "mylib.js" (you could actually omit the name and it would take the filename). I have briefly reviewed the code and we collect all js stuff at the end and create a nbJsFromCodeOwnFile block. We could add to this block a field staticJs = true (with optional field of filename), in case it sees the nbJsStatic is executed (which adds itself the same fields to doc context). Then we would need to modify the compileNimToJs to check for staticJs context and in that case change destination folder and filename and skip removal of js and adding it to js. This basically makes any JsCodeOwnFile (including karax blocks) a block that you can customize to make it write a static js. Actually probably nbJsStatic should add a staticGlobal field that is checked by nimCollectAllJs so that we do not run into risks if we inherit block context from doc context (which at the moment I do not recall if we do, but it is something we could decide to do at some point). |
I think I had a different use-case in mind then. What you propose is a nimib file that is exclusively for showing the creation of a js file that can be used as a library by other files? But one complication with this is: how do we easily access the library functions? We have to use |
Yes, this is the use case I was thinking of, but now you put all sorts of doubts in what I thought :) I will try think about it more and come up with a better explanation/use case |
Hehe 😅 Yes concrete examples are always the best. I don't have any either atm, but it just felt limiting to have it either no nbJs or all nbJs is compiled to a static file. |
our default behaviour of Js blocks is to write a nim file, compile to js, then read the js file, incroporate in html and delete it. I think this is the correct approach but in some cases you might want to generate a js file that you want to keep as a static asset. the standard use case would be a multi page site where in one notebook you generate (and "discuss/document") a js library and in other pages you just use it.
we would need to think about an api.
The text was updated successfully, but these errors were encountered: