prelive.nvim
is a simple luv-based development server with live reloading for Neovim.
- Provides a file server with automatic reloading functionality, ensuring your changes are immediately reflected in the browser.
- Implemented in Lua using
vim.uv
, eliminating the need for Node.js or other external tools. - Requests are processed asynchronously, so they won't interrupt your editing.
- Offers an API for integration with other plugins, allowing you to build more advanced workflows.
Important
For security reasons, it is recommended to use this plugin only in a trusted environment.
- Neovim v0.10.1 or later
Install the plugin using your favorite package manager:
lazy.nvim:
{
"hat0uma/prelive.nvim",
opts = {},
cmd = {
"PreLiveGo",
"PreLiveStatus",
"PreLiveClose",
"PreLiveCloseAll",
"PreLiveLog",
},
}
vim-plug:
Plug 'hat0uma/prelive.nvim'
lua require('prelive').setup {}
The setup
function accepts a table with the following options:
require('prelive').setup {
server = {
--- The host to bind the server to.
--- It is strongly recommended not to expose it to the external network.
host = "127.0.0.1",
--- The port to bind the server to.
--- If the value is 0, the server will bind to a random port.
port = 2255,
},
http = {
--- maximum number of pending connections.
--- If the number of pending connections is greater than this value, the client will receive ECONNREFUSED.
--- @type integer
tcp_max_backlog = 16,
--- tcp recv buffer size.
--- The size of the buffer used to receive data from the client.
--- This value is used for `vim.uv.recv_buffer_size()`.
--- @type integer
tcp_recv_buffer_size = 1024,
--- http keep-alive timeout in milliseconds.
--- If the client does not send a new request within this time, the server will close the connection.
--- @type integer
keep_alive_timeout = 60 * 1000,
--- request body size limit
--- If the request body size exceeds this value, the server will return 413 Payload Too Large.
--- @type integer
max_body_size = 1024 * 1024 * 1,
--- request line size limit
--- The request line consists of the request method, request URI, and HTTP version.
--- If the request line size exceeds this value, the server will return 414 URI Too Long.
--- @type integer
max_request_line_size = 1024 * 4,
--- header field size limit (key + value)
--- If the size of a header field exceeds this value, the server will return 431 Request Header Fields Too Large.
--- @type integer
max_header_field_size = 1024 * 4,
--- max header count.
--- If the number of header fields exceeds this value, the server will return 431 Request Header Fields Too Large.
--- @type integer
max_header_num = 100,
--- max chunk-ext size limit for chunked body
--- If the size of a chunk-ext exceeds this value, the server will return 400 Bad Request.
--- @type integer
max_chunk_ext_size = 1024 * 1,
},
log = {
--- The log levels to print. see `vim.log.levels`.
print_level = vim.log.levels.WARN,
--- The log levels to write to the log file. see `vim.log.levels`.
file_level = vim.log.levels.DEBUG,
--- The maximum size of the log file in bytes.
--- If 0, it does not output.
max_file_size = 1 * 1024 * 1024,
--- The maximum number of log files to keep.
max_backups = 3,
},
}
:PreLiveGo [dir] [file]
: Start the server and open the specified file in the browser. If no arguments are provided, the current working directory (cwd) is served and the current buffer file is opened in the browser.:PreLiveStatus
: Show the status of the served directories and open one in the browser.:PreLiveClose
: Select a directory to stop serving.:PreLiveCloseAll
: Stop serving all directory.:PreLiveLog
: Open the log file in a new tab.
Start the server with the current working directory and open the current buffer file in the browser:
:PreLiveGo
Start the server and serve a specific directory:
:PreLiveGo ./folder
Serve a specific file and open it in the browser:
:PreLiveGo ./folder file.html
The following functions are available for use in Lua:
local prelive = require('prelive')
-- Start the server and open the specified file in the browser.
-- If { watch = false }, the server will not watch the file for changes. in this case, you need to call `prelive.reload` manually.
local opts = { watch = true }
prelive.go(dir, file, opts)
-- Show the status of the served directories and open one in the browser.
prelive.status()
-- Select a directory to stop serving. (using `vim.ui.select`)
prelive.select_close()
-- Stop serving the specified directory.If no arguments are provided, It stops all.
prelive.close()
-- Open the log file in a new tab.
prelive.open_log()
-- Force reload the served directory.
prelive.reload(dir)
Contributions are welcome! Please open an issue or submit a pull request on GitHub.