toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 260 forks source link

Does RazorLight supports blazor components ? #318

Closed martasp closed 4 years ago

martasp commented 4 years ago

I want to render .razor files.

jzabroski commented 4 years ago

@martasp I haven't tried it. Please let me know how you make out.

martasp commented 4 years ago

Heres how I made a library that compiles razor components in runtime.

LivePreview

In react we have hot module replacement this feature allows us to change code and see changes immediately in your browser. We can make a similar feature in blazor using Roslyn compiler. Compiling down razor components in runtime and serving with WebSockets on every file change using file watcher.

How it works

It uses razor engine version 3 to compile components to c# classes. Then using Roslyn compiler I compiled down those classes to assembly. Finally, I loaded the app.razor component from an assembly with reflection and with Steve Sanderson Test host modified library I turned component to plain HTML. To serve HTML files in realtime I used WebSockets to have a full-duplex communication.

How can it be better 

Fixing routes instead of using /preview, this could be implemented by injecting WebSocket client into every HTTP request context.

In Blazor web assembly maybe we can load and unload assemblies in the browser?

Using two build servers one for fast previewing and another server with dotnet watch build for actual real longer builds.

In Blazor web assembly maybe we can load and unload assemblies in the browser?

Source: https://github.com/martasp/BlazorLiveReload

jzabroski commented 4 years ago

Looks good but where are you using RazorLight?

toddams commented 4 years ago

Blazor is a relatively new stuff, and we've never did anything specific to support it. It might be a good idea to investigate this direction, but it is only possible after going stable in 2.0

AntonitoMt commented 3 years ago

Hello. I am looking a way to compile in runtime a razor markup that I have in a string and convert it into an assembly. Could I do it with this tool? Thanks

jzabroski commented 3 years ago

@AntonitoMt I am pretty confused as to why you put this question on a closed issue unrelated to your question. We don't support precompilation currently. In theory, if you want to submit a PR, look at the Razorlight.Precompile.csproj to add support for that

AntonitoMt commented 3 years ago

I apologize. My question was regarding the tool BlazorLiveReload posted by martasp. Thank you

jzabroski commented 3 years ago

I apologize as well. BlazorLiveReload is a blazor-specific feature. Blazor is technically a separate feature from Razor itself. I still think you could get very far if you decided to submit a PR to help along the Razorlight.Precompile project.