## Problem The plugin requires users to install Node.js and the `live-server` npm package globally. This is a heavyweight external dependency for what amounts to a simple local dev-server workflow, and it creates friction for users who don't otherwise need Node.js. ## Solution Replace the npm shell-out with a pure-Lua HTTP server built on `vim.uv` (libuv bindings), eliminating all external dependencies. The new server supports static file serving, SSE-based live reload, CSS hot-swap without full page reload, directory listings, and recursive file watching with configurable debounce. Minimum Neovim version is bumped to 0.10 for `vim.uv` and `vim.ui.open`. The old `args`-based config is automatically migrated with a deprecation warning. Closes #28.
36 lines
1 KiB
Lua
36 lines
1 KiB
Lua
if vim.fn.has('nvim-0.10') == 0 then
|
|
vim.api.nvim_echo({
|
|
{
|
|
'live-server.nvim requires Neovim >= 0.10. ' .. 'Pin to v0.1.6 or upgrade Neovim.',
|
|
'ErrorMsg',
|
|
},
|
|
}, true, {})
|
|
return
|
|
end
|
|
|
|
if vim.g.loaded_live_server then
|
|
return
|
|
end
|
|
vim.g.loaded_live_server = 1
|
|
|
|
vim.api.nvim_create_user_command('LiveServerStart', function(opts)
|
|
require('live-server').start(opts.args)
|
|
end, { nargs = '?' })
|
|
|
|
vim.api.nvim_create_user_command('LiveServerStop', function(opts)
|
|
require('live-server').stop(opts.args)
|
|
end, { nargs = '?' })
|
|
|
|
vim.api.nvim_create_user_command('LiveServerToggle', function(opts)
|
|
require('live-server').toggle(opts.args)
|
|
end, { nargs = '?' })
|
|
|
|
vim.keymap.set('n', '<Plug>(live-server-start)', function()
|
|
require('live-server').start()
|
|
end, { desc = 'Start live server' })
|
|
vim.keymap.set('n', '<Plug>(live-server-stop)', function()
|
|
require('live-server').stop()
|
|
end, { desc = 'Stop live server' })
|
|
vim.keymap.set('n', '<Plug>(live-server-toggle)', function()
|
|
require('live-server').toggle()
|
|
end, { desc = 'Toggle live server' })
|