live-codes / livecodes

Code Playground That Just Works!
https://livecodes.io
MIT License
783 stars 66 forks source link

Feature: Export as module #432

Open aehlke opened 1 year ago

aehlke commented 1 year ago

Type of feature

✨ Feature

Current behavior

Can only export as variations of full HTML pages.

Suggested feature

It would be valuable to be able to edit a script which can then be built and exported as a reusable module rather than only as a webpage. In this case, markup/style would either be unneeded or used during dev only for testing integrating the module. I'd like to be able to define some functions that I can then export, host somewhere, and reuse as imports in another livecodes session.

Additional context

No response

Code of Conduct

Contributing Docs

hatemhosny commented 1 year ago

There are currently multiple ways to re-use scripts as modules that can be imported in other projects:

I hope this helps. If you have other suggestions or ideas, I'd be happy to know about.

aehlke commented 11 months ago

jsdelivr works well! thank you

My next question is how I could use the outputs of these together with another language, without having them isolated into separate sandboxes. Is there a good way to combine the built JS/wasm outputs together into one HTML file besides statically combining the rendered files outside of livecodes? for example, in order to run both python/pyodide & JS in the same document/frame. I understand it's not the focus of livecodes but maybe there's a simple way to extend it with this behavior. Thanks for your guidance

edit: I'd also like to use jsdelivr.gh: / skypack: prefixes for imports in these modules. How do you also reuse their module maps?

hatemhosny commented 11 months ago

As you mentioned, running multiple scripts/multi-file projects are out of the focus of LiveCodes. However, you may use something like the methods described above to "import/re-use" code.

In addition, since you can use HTML, there is nothing that prevents you from adding a script tag there and add the JS code you want.

Example: https://livecodes.io/?x=id/cird58vjmfh (edit: added import from skypack) In this example, you can increment the same counter from python and from JS code. Also, module resolution works in script tags added to HTML (the example imports from skypack).

Is that what you mean?