Skip to main content

Prettier

info

You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed.

Alternatively, you can add it to your lazy.nvim imports
lua/config/lazy.lua
require("lazy").setup({
spec = {
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "lazyvim.plugins.extras.formatting.prettier" },
{ import = "plugins" },
},
})

Options

Additional options for this extra can be configured in your lua/config/options.lua file:

lua/config/options.lua
-- Enable the option to require a Prettier config file
-- If no prettier config file is found, the formatter will not be used
vim.g.lazyvim_prettier_needs_config = false

Below you can find a list of included plugins and their default settings.

caution

You don't need to copy the default settings to your config. They are only shown here for reference.

mason.nvim

opts = { ensure_installed = { "prettier" } }

conform.nvim (optional)

conform

opts = function(_, opts)
opts.formatters_by_ft = opts.formatters_by_ft or {}
for _, ft in ipairs(supported) do
opts.formatters_by_ft[ft] = { "prettier" }
end

opts.formatters = opts.formatters or {}
opts.formatters.prettier = {
condition = function(_, ctx)
return M.has_parser(ctx) and (vim.g.lazyvim_prettier_needs_config ~= true or M.has_config(ctx))
end,
}
end

none-ls.nvim (optional)

none-ls support

opts = function(_, opts)
local nls = require("null-ls")
opts.sources = opts.sources or {}
table.insert(opts.sources, nls.builtins.formatting.prettier)
end