- Notifications
You must be signed in to change notification settings - Fork25
Simple development server with live-reload capability for Julia.
License
JuliaDocs/LiveServer.jl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a simple and lightweight development web-server written in Julia,based onHTTP.jl.It has live-reload capability, i.e. when modifying a file, every browser (tab)currently displaying the corresponding page is automatically refreshed.
LiveServer is inspired from Python'shttp.server
and Node'sbrowsersync
.
To install it in Julia ≥ 1.6, use the package manager with
pkg> add LiveServer
Infrequently, youmay see an error message in your console while using LiveServer that does notinterrupt the server and does not otherwise affect your ability to see updates in the browser.This error message will look like
┌ LogLevel(1999): handle_connection handler error│ exception =│ IOError: write: broken pipe (EPIPE)
You can basically ignore this message, it's a problem withHTTP.jl.
If your application depends on LiveServer and you'd like to avoid having that kind of messages being shown to your users, you can consider usingLoggingExtras.jl whichallows you to filter out messages based on their provenance.
We experimented with shipping LoggingExtras in LiveServer but ended up rolling that back as it madeother applications less stable.
For Julia< 1.6
, you can use LiveServer's version 0.9.2:
pkg> add LiveServer@0.9.2
For Julia[1.0, 1.3)
, you can use LiveServer's version 0.7.4:
pkg> add LiveServer@0.7.4
LiveServer is a small package and fast to load with one main functionality (serve
),it can be convenient to make it a shell command: (I'm using the namelss
here butyou could use something else):
alias lss='julia -e "import LiveServer as LS; LS.serve(launch_browser=true)"'
you can then uselss
in any directory to show a directory listing in your browser,and if the directory has anindex.html
then that will be rendered in your browser.
The main functionLiveServer
exports isserve
which starts listening to the currentfolder and makes its content available to a browser.The following code creates an example directory and serves it:
julia>using LiveServerjulia> LiveServer.example()# creates an "example/" folder with some filesjulia>cd("example")julia>serve()# starts the local server & the file watching✓ LiveServer listening on http://localhost:8000/ ... (use CTRL+C to shut down)
Open a Browser and go tohttp://localhost:8000/
to see the content being rendered;try modifying files (e.g.index.html
) and watch the changes being rendered immediately in the browser.
In the REPL:
julia>using LiveServerjulia>serve(host="0.0.0.0", port=8001, dir=".")# starts the remote server & the file watching✓ LiveServer listening on http://0.0.0.0:8001... (use CTRL+C to shut down)
In the terminal:
julia -e'using LiveServer; serve(host="0.0.0.0", port=8001, dir=".")'
Open a browser and go tohttps://localhost:8001/ to see the rendered content of index.html or,if it doesn't exist, the content of the directory.You can set the port to a custom number.This is similar to thehttp.server
in Python.
servedocs
is a convenience function that runsDocumenter
along withLiveServer
to watchyour doc files for any changes and render them in your browser when modifications are detected.
Assuming you are indirectory/to/YourPackage.jl
, that you have adocs/
folder asprescribed byDocumenter.jl andLiveServer
installed in your global environment, you can run:
$ juliapkg> activate docsjulia>using YourPackage, LiveServerjulia>servedocs()[ Info: SetupBuildDirectory: setting up build directory.[ Info: ExpandTemplates: expanding markdown templates....└ Deploying: ✘✓ LiveServer listening on http://localhost:8000/ ... (use CTRL+C to shut down)
Open a browser and go tohttp://localhost:8000/
to see your docs being rendered;try modifying files (e.g.docs/index.md
) and watch the changes being rendered in the browser.
To run the server with one line of code, run:
$ julia --project=docs -ie 'using YourPackage, LiveServer; servedocs()'
Note: this works withLiterate.jl as well.Seethe docs.
See also issue #135 and related PRs.
servedocs()
, navigate to literate, images should showserve()
navigate manually todocs/build/
should show, remove trailing slash in URLdocs/build
should redirect todocs/build/
serve(dir=...)
should work + when navigating to assets etc
About
Simple development server with live-reload capability for Julia.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.