prettier-plugin-vue is a Prettier plugin designed to enhance the formatting capabilities for Vue Single File Components (SFCs) beyond Prettier's default behavior. Currently at version 1.1.6, this plugin enables developers to precisely control which blocks within an SFC are formatted by Prettier. Its primary differentiator is the `vueExcludeBlocks` option, which allows specific sections (like `<style>` or `<template>`) to be ignored during formatting. This feature is particularly useful for integrating Prettier with other specialized linters such as `eslint` and `stylelint`, preventing formatting conflicts that might arise from multiple tools acting on the same code sections. The plugin autoloads in most setups, streamlining its adoption. While not explicitly stating a release cadence, its presence on npm and active GitHub actions suggest ongoing maintenance, providing a stable solution for Vue formatting challenges. It avoids common issues with IDE-specific formatters by handling exclusions at the Prettier configuration level.
npm install prettier-plugin-vueVerified import paths — ran on the pinned version, not inferred.
This quickstart guides you through installing the plugin, configuring Prettier to exclude style blocks in Vue SFCs, and then demonstrates running Prettier on a sample Vue file to show which blocks are formatted and which are skipped.
To ensure the plugin is loaded, explicitly add `prettier-plugin-vue` to your Prettier configuration's `plugins` array. For CommonJS configs: `plugins: [require('prettier-plugin-vue')]`. For ESM configs: `plugins: ['prettier-plugin-vue']`.If you wish for Prettier to format `<style>` blocks within your Vue SFCs, you must explicitly remove `'style'` from the `vueExcludeBlocks` array in your Prettier configuration (e.g., `vueExcludeBlocks: []`). Be aware of potential conflicts if you are also using a style linter.
Ensure that `vueExcludeBlocks` is correctly defined as an array of string literals in your `.prettierrc` or `prettier.config.js` file, for example: `vueExcludeBlocks: ['style', 'template']`.
First, ensure `prettier-plugin-vue` is installed as a `devDependency` (`npm install --save-dev prettier-plugin-vue`). Then, explicitly configure it in your `prettier.config.js`: `module.exports = { plugins: [require('prettier-plugin-vue')] }`.To enable Prettier to format `<style>` blocks, you need to override the default configuration. In your `prettier.config.js`, set `vueExcludeBlocks` to an empty array or remove `'style'` from it: `module.exports = { vueExcludeBlocks: [] }`.Use CommonJS `require()` syntax for loading plugins in `prettier.config.js`: `module.exports = { plugins: [require('prettier-plugin-vue')] }`. If you prefer ESM syntax, rename your configuration file to `prettier.config.mjs`.