Skip to content

About

CSSOrganizer enables configurable sorting of CSS style blocks in both CSS files and Vue Single File Components (SFCs).

Resources

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

CSSOrganizer

npm License: MIT

Consistent CSS property order across your project. CSSOrganizer sorts declarations in .css files and in plain CSS <style> blocks in Vue single-file components. It supports Tailwind CSS @apply and has no runtime dependencies.

🚀 Quick start

Install CSSOrganizer as a development dependency and run it from your project:

npm install --save-dev @derkatzelp/cssorganizer
npx css-organizer

By default, CSSOrganizer uses the current working directory as the project root. To use another directory, pass --root (or -r). Relative paths are resolved from the directory where you run the command:

npx css-organizer --root "../my project"

CSSOrganizer searches the configured folders and their subfolders. It edits files in place and skips writing files whose output is unchanged. Review the diff before committing: moving declarations can affect the CSS cascade, especially when shorthand and longhand properties are mixed.

⚙️ Configuration

Both override files are optional. Place them in the project root to use them instead of the bundled defaults.

File selection and logging

Copy the bundled config.json to config.cssorg.json and adjust the values you need. The override replaces the entire default file, so keep all keys.

Option Default Description
cssFolderPath "./src/assets" Folder to scan for .css files, relative to the project root
vueFolderPath "./src/components" Folder to scan for .vue files, relative to the project root
sortCssFiles true Process CSS files
sortVueFiles true Process Vue single-file components
showLogFiles true Log each file whose content changed
showLogFolders true Log each processed folder

Property order

Copy grouping.json to grouping.cssorg.json. CSSOrganizer reads the groups array in order and follows each group's properties list. Unlisted declarations and @apply appear before listed properties, preserving their relative order. Groups define the sort order; they do not insert headings or comments.

✨ Example

Before

.card {
    color: navy;
    width: 20rem;
    display: block;
    position: relative;
}

After

.card {
    position: relative;
    display: block;
    width: 20rem;
    color: navy;
}

📌 Limitations

  • SCSS, Sass, and Less are not supported. Use CSSOrganizer only on Vue files with plain CSS styles.
  • Only the first <style> block in a Vue file is processed. Put its opening and closing tags on separate lines.
  • Declarations inside nested rules, such as rules within @media, are not reordered.

Contributing and license

Report bugs or suggest improvements on GitHub. CSSOrganizer is licensed under the MIT License and inspired by 9elements’ CSS Rule Order.

About

CSSOrganizer enables configurable sorting of CSS style blocks in both CSS files and Vue Single File Components (SFCs).

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages