Skip to content

[FAQ] Compatibility with prettier-plugin-tailwindcss #33

@ony3000

Description

@ony3000

Can I use this plugin with prettier-plugin-tailwindcss?

Of course! However, there are a few notes.

  1. Languages that can be used with prettier-plugin-tailwindcss are limited to:

    • JavaScript
    • TypeScript
    • Vue (v0.3.0 or higher)
    • Astro (v0.6.0 or higher)
    • Angular, HTML, Svelte (v0.7.0 or higher)

    Support for other languages requires further development.

  2. You need to add prettier-plugin-merge to your Prettier configuration.

    This is because if two or more plugins are configured to format a particular language, Prettier will only use the last of those plugins.

    So, for example, if you configure it like this, only prettier-plugin-tailwindcss will be used.

    {
      "plugins": [
        "prettier-plugin-classnames", // ignored
        "prettier-plugin-tailwindcss"
      ]
    }

    By reordering the two plugins, now only prettier-plugin-classnames is used.

    {
      "plugins": [
        "prettier-plugin-tailwindcss", // ignored
        "prettier-plugin-classnames"
      ]
    }

    I created prettier-plugin-merge to overcome this limitation of Prettier.

    prettier-plugin-merge uses the plugins listed before it sequentially to format and merge them.

    So, to allow Prettier to use prettier-plugin-merge, change the configuration as follows:

    {
      "plugins": [
        "prettier-plugin-tailwindcss",
        "prettier-plugin-classnames",
        "prettier-plugin-merge"
      ]
    }

    Now Prettier will only use prettier-plugin-merge among the three plugins, but prettier-plugin-merge will use prettier-plugin-tailwindcss and prettier-plugin-classnames sequentially.

    So the class names will be sorted first and then wrapped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions