Skip to content

Using with Vue SFCs + VSCode #19

@crisvp

Description

@crisvp

Hiya Tony

First, thanks for the handy plugin. It helps relieve eye-twitches whenever I see <hr />

I had a bit of a journey getting the plugin to work with Vue SFCs and VS Code, but I think I got there. I thought I'd share it in case you want to add it to the docs or in case it helps with getting it to work with other not-quite-HTML files.

First, Vue SFCs required a fairly simple monkey-patch slash settings adjustment from prettier.config.mjs:

import * as voidPlugin from '@awmottaz/prettier-plugin-void-html';
import { parsers } from 'prettier/plugins/html';

voidPlugin.languages.extensions = ['.html', '.vue'];
voidPlugin.parsers.vue = parsers.vue;

export default {
  plugins: [voidPlugin],
  // the rest of the config
}

This was enough to get everything to work the way I wanted it to work ... from the command line.

As it turns out, the VS Code prettier extension (esbenp.prettier-vscode), possibly in combination with multi-root workspaces, does not like to load plugins (or this plugin anyway) and has this to say on the matter: "{}".

After much trial and error, the following seemed to work;

  1. Create a void.mjs:
import * as voidPlugin from '@awmottaz/prettier-plugin-void-html';
import { parsers } from 'prettier/plugins/html';

voidPlugin.languages.extensions = ['.html', '.vue'];
voidPlugin.parsers.vue = parsers.vue;

export default voidPlugin;
  1. Load it -- by string reference -- from prettier.config.mjs
export default {
  plugins: ["./void.mjs"],
  // the rest of the config
}

That finally made VS Code happy, and it now formats-on-saves the slashes away from my <hr/> so that I don't have to disable half my eslint config. 🥳

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions