Is there a weave live preview server?

I want to write a document using weave, but currently I have to manually rerun the “save to file” or “show preview” commands in vscode.

Is there a server which watches the file and recompiles the changed document?
Maybe even using some caching.

At the moment it seems like vscode is starting a new julia session to rerun the weave commands.
The reason I think this happens is that is takes always a lot of time when running the chunks containing Plots.jl etc

I wrote a crude script to watch for save events to trigger a recompile of the document.
Maybe it is helpful for someone.

To view the generated document I use the Liveserver extension in vscode.

using Weave
using FileWatching

while true 
    jmdfilepth = normpath("mydoc.jmd")
    status = watch_file(jmdfilepth)
    outpath = "out"
    if status.changed
        @info "change detected"
        weave(jmdfilepth, doctype="md2html", out_path= "out",cache=:none,fig_path="fig")
        for folder in filter((x)->startswith(x,"jl_"),readdir(outpath))
            tmpdir = joinpath(outpath,folder)
            @info "delete $tmpdir"
            rm(tmpdir,recursive=true)
        end
    end
    sleep(1)
end

This might be helpful Livereload with Weave.jl

Unfortunately I didn’t have time to have a look at it, since I focus on two projects in R right now, but it looks promising!

1 Like