tomhodgins / css-package-manager

A Package Manager for CSS Extensions
26 stars 1 forks source link

CSS Package Manager

A plan for a package manager for CSS dependencies and libraries.

What is it?

This is a repository for brainstorming the requirements and look and feel of a package manager for CSS. You can think of it as something like npm, but for CSS packages instead of JavaScript.

Why does CSS need a package manager?

Presently CSS authors use a number of different tools:

Also there are other tools, like the CSS-in-JS ecosystem, where style information is embedded inside other languages, workflows, or frameworks.

But there's no coordinated place where your entire CSS workflow can be described, all of its dependencies listed in a way that can be reasoned about, or instructions for how your styles should be packaged and delivered with all their dependencies.

What would it do?

A package manager for CSS would let authors:

Imagine a scenario in which one person, let's name this person Cas, loves making Layout API worklets for different tiled layouts. Imagine Cas has made hexagonal layouts, triangular layouts, pentagonal layouts, etc and publishes these Layout API worklets for others to use.

Next imagine a game designer named Steve finds Cas's tiled layout worklets and thinks they'd be the perfect way to design and build game boards of various sizes and shapes for in-browser games. So Steve publishes a package that consume's Cas's tiled layout worklets and provides a 'game board builder' interface that has a few easy configurations.

Now you come along, you want to recreate a specific board game experience in the browser that uses a triangular tiled board. Imagine if in your stylesheet all you had to define was this:

main {
  display: layout(game-board);
  --shape: triangle;
  --size: 100;
}

And once you ran that through a tool, it fetches both Steve's game-board package, which itself also requires Cas's triangular tile layout.

To take things one step further, even if Steve's game-board layout supports triangular, hexagonal, and pentagonal tiled layouts, since only the triangular mode was used it only bundles that code, leaving the code for supporting hexagonal layouts or pentagonal layouts out of your final build.

What would it look like?

That's a great question - currently there are many different ideas of how this could be exposed in valid CSS syntax inside CSS stylesheets. Any of the following might be ways this could work:

How does it work?

That part I'm not sure about - I've never built a package manager before, but thankfully many already exist that can be learned from both in what to do and what not to do. Here are two that we can probably learn from as the flesh this one out:

How can I help?

Open an issue to discuss any idea related to this!