Define component from string
Right now, WebC accepts file paths for component definitions and reads the file during compilation. It would be nice to have a way to pass the component source code directly as a string instead.
webc.defineComponent("my-component", "my-component.webc", "Hello <slot></slot>!")
You can do the following using the JavaScript API:
let component = new WebC();
component.setContent("Hello <slot></slot>!")
Does that cover your use case?
This makes sense to me! Not all components will exist on the file system
I was looking for this API when I was playing around yesterday. From a consistency perspective it makes sense to offer an API for both files and programmatic definition, like there is for content already.
Would this make building a repl/playground easier since everything can be done in memory, without the assumption of a file system?
Would a REPL/playground require WebC to be able to be run in a browser environment? Currently, it's pretty tied to a Node.js environment.
I'm not familiar enough with the codebase to say. I guess you could create a repl on Stackblitz or something if it does require a node env. I think it'd be a nice goal for it to be able to run in the browser though.
I agree, it would be nice to run WebC in a browser (I don't even have a good reason for this beyond "it feels right"), but I also think this depends on what WebC wants to accomplish/be.
Should WebC go down the route of (at some arbitrary point the future that is) be a hybrid tool that runs in parts in a browser environment and/or in parts in a Node environment. Some things (e.g. reading from a file system) make only sense in either.
As a good example of a tool/library that is structured as a kind of hybrid between browser and Node environments, I'd like to point to https://mswjs.io/. Notably, it's written in a way that importing from msw imports browser-running code while importing from msw/node imports Node-running code.