csspin-rails
Pin CSS packages from npm into a Rails app's vendor/assets/stylesheets — without Node.js.
Works like importmap-rails, but for CSS. Packages are fetched from jsDelivr.
Installation
Add to your Gemfile:
gem "csspin-rails"
Then run:
bundle install
Usage
# Pin a package (latest version)
bundle exec csspin pin sourdough-toast
# Pin a specific version
bundle exec csspin pin sourdough-toast@2.0.7
# Pin a scoped package
bundle exec csspin pin @37signals/lexxy
CSS is saved to vendor/assets/stylesheets/<package>.css.
If you want bin/csspin, run bundle binstubs csspin-rails first.
After pinning, the CLI prints integration snippets:
Sprockets snippet: *= require sourdough-toast
Sass snippet: @import "sourdough-toast";
CLI
Usage: csspin pin <package|package@version>
Commands:
pin <package|package@version> Download a CSS package into vendor/assets/stylesheets
Options:
-v, --version Show version
-h, --help Show this help
How it works
- Parses the package name and optional version
- Resolves candidate URLs on jsDelivr (
/dist/<pkg>.css, then the bare package URL) - Downloads the first successful CSS response (follows redirects, validates content-type)
- Writes the file to
vendor/assets/stylesheets/
Development
bundle install
bundle exec standardrb
bundle exec rake test
Releasing
This repo publishes via GitHub Actions when you push a tag matching v* (see .github/workflows/release.yml).
- Update
lib/csspin/version.rb - Run
bundle exec rake test(and any linting you want) - Commit
- Tag:
git tag vX.Y.Z - Push commit:
git push origin HEAD - Push tag:
git push origin vX.Y.Z
License
The gem is available as open source under the terms of the MIT License.