A lightweight Neovim plugin to serve HTML files using live-server, optimized for Bun.js.
- Bun (instead of npm)
live-serverglobally installed via Bun
bun add -g live-serverInstall the plugin using lazy.nvim:
require("lazy").setup({
{
"RoyRoki/live-server-bun-nvim",
event = "VeryLazy",
build = ":LiveServerInstall",
config = function()
require("live-server-nvim").setup({})
end,
},
})live-server-nvim works out of the box but allows customization if needed:
require("live-server-nvim").setup({
custom = {
"--port=8080", -- Set custom port
"--no-css-inject", -- Disable CSS injection
},
serverPath = vim.fn.stdpath("data") .. "/live-server/", -- Default
open = "folder", -- "folder" | "cwd"
})More customization options available:
🔗 live-server CLI options
| Command | Description |
|---|---|
:LiveServerStart |
Start the server with the correct HTML file |
:LiveServerStop |
Stop the server |
:LiveServerRestart |
Restart the server |
:LiveServerOpen |
Open the served HTML file in the browser |
Example mappings:
vim.keymap.set("n", "<leader>ls", ":LiveServerStart<CR>", { noremap = true, silent = true, desc = "Start Live Server" })
vim.keymap.set("n", "<leader>lx", ":LiveServerStop<CR>", { noremap = true, silent = true, desc = "Stop Live Server" })
vim.keymap.set("n", "<leader>lr", ":LiveServerRestart<CR>", { noremap = true, silent = true, desc = "Restart Live Server" })
vim.keymap.set("n", "<leader>lo", ":LiveServerOpen<CR>", { noremap = true, silent = true, desc = "Open Live Server in Browser" })- Detects the correct HTML file to serve:
- If you're in an HTML file → serve the current file.
- If not, it looks for
index.htmlin the project. - If no
index.html, it serves the first available HTML file. - If no HTML files are found, it shows a warning.
- Opens the correct HTML file in your browser.
- Prevents multiple servers from running.
- Improves logging for better debugging.
Feel free to contribute by opening an issue or PR at:
🔗 GitHub Repo
🚀 Happy coding!