A plan for a package manager for CSS dependencies and libraries.
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.
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.
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.
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:
a package.css
file to define folder-wide or project-wide how style information in that folder or project should be
custom at-rules in CSS that provide a declarative way to describe importing and configuring external dependencies used in that stylesheet
can you think of other ways? open an issue to discuss!
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:
Open an issue to discuss any idea related to this!