Rake tasks to vendor Bootstrap CSS and JS into your Rails app. No asset pipeline, no npm, no build system. Just static files in vendor/.
Add to your Gemfile:
gem 'bootstrap-vendor'Then:
bundle installIn a Rails app, the rake tasks are loaded automatically via Railtie.
rake bootstrap:vendorThis creates a .bootstrap-version file and downloads the latest Bootstrap CSS and JS into vendor/stylesheets/ and vendor/javascript/.
Add Bootstrap to your asset paths. In config/initializers/assets.rb:
Rails.application.config.assets.paths << Rails.root.join('vendor/stylesheets')
Rails.application.config.assets.paths << Rails.root.join('vendor/javascript')Or with importmaps, pin the JS in config/importmap.rb:
pin 'bootstrap', to: 'bootstrap.bundle.js'And add a stylesheet link in your layout:
<%= stylesheet_link_tag 'bootstrap', 'data-turbo-track': 'reload' %>Add the gem:
gem install bootstrap-vendorCreate a Rakefile (or add to an existing one):
require 'bootstrap/vendor'
load 'tasks/bootstrap.rake'Then use the rake tasks as normal:
rake bootstrap:vendorzsh interprets [] as glob patterns. Escape the brackets when passing arguments to rake tasks:
rake 'bootstrap:init[overwrite]'
rake bootstrap:init\[overwrite\]
noglob rake bootstrap:init[overwrite]bootstrap:vendor— do it all shortcutbootstrap:version— print current versionbootstrap:latest— print latest upstream versionbootstrap:status— compare current to latestbootstrap:init— create .bootstrap-versionbootstrap:install— download filesbootstrap:update— update filesbootstrap:uninstall— remove files
The opinionated, does-it-all shortcut. Creates .bootstrap-version, downloads the latest Bootstrap files, and you're done.
rake bootstrap:vendorPrints the current version from .bootstrap-version.
rake bootstrap:version
# 5.3.8Prints the latest known Bootstrap version. Accepts an optional constraint.
rake bootstrap:latest
# 5.3.8
rake bootstrap:latest[5]
# 5.3.8
rake bootstrap:latest[4]
# 4.6.2
rake bootstrap:latest[5.2]
# 5.2.3Compares your current version to the latest upstream.
rake bootstrap:status
# Current version 5.3.8 is up to date
rake bootstrap:status
# Current version 5.2.3 is behind latest version 5.3.8Creates a .bootstrap-version file. Defaults to the latest version.
rake bootstrap:init
# A .bootstrap-version file was created.
# Version: 5.3.8
rake bootstrap:init[4]
# A .bootstrap-version file was created.
# Version: 4.6.2
rake bootstrap:init[overwrite]
# Overwrites an existing .bootstrap-versionDownloads Bootstrap CSS and JS files. Fails if already installed (use update instead).
rake bootstrap:installDownloads Bootstrap CSS and JS files, overwriting existing ones.
rake bootstrap:update
# Bootstrap updated from 5.3.5 to 5.3.8Removes vendored Bootstrap files and .bootstrap-version.
rake bootstrap:uninstallBy default, these files are downloaded:
vendor/stylesheets/bootstrap.css
vendor/stylesheets/bootstrap.css.map
vendor/javascript/bootstrap.bundle.js
vendor/javascript/bootstrap.bundle.js.mapCustomize which files are downloaded with environment variables. These are the defaults:
| ENV variable | Default | Effect |
|---|---|---|
BOOTSTRAP_VENDOR_CSS_LTR |
true |
Download LTR CSS |
BOOTSTRAP_VENDOR_CSS_RTL |
false |
Download RTL CSS |
BOOTSTRAP_VENDOR_CSS_MAP |
true |
Download CSS source maps |
BOOTSTRAP_VENDOR_CSS_MIN |
false |
Download minified CSS |
BOOTSTRAP_VENDOR_JS_BUNDLE |
true |
Download bundle (includes Popper) vs plain |
BOOTSTRAP_VENDOR_JS_MAP |
true |
Download JS source maps |
BOOTSTRAP_VENDOR_JS_MIN |
false |
Download minified JS |
At least one of CSS_LTR or CSS_RTL must be true.
Example: download minified files without source maps:
BOOTSTRAP_VENDOR_CSS_MIN=true BOOTSTRAP_VENDOR_CSS_MAP=false BOOTSTRAP_VENDOR_JS_MIN=true BOOTSTRAP_VENDOR_JS_MAP=false rake bootstrap:installFiles are downloaded from multiple sources with automatic fallback for resilience:
- jsdelivr CDN (npm)
- jsdelivr CDN (GitHub)
- GitHub raw files
- GitHub releases (zip)
Pin a specific source with:
BOOTSTRAP_VENDOR_SOURCE=github_raw rake bootstrap:installValid source names: jsdelivr_npm, jsdelivr_github, github_raw, github_api.
Most tasks accept an optional path argument. By default, tasks operate in the current directory. Pass a path to target a different location:
rake 'bootstrap:vendor[public/assets]'
rake 'bootstrap:version[public/assets]'The .bootstrap-version file and vendor/ directories are created relative to the given path.
Tasks that accept path: vendor, version, status, init, install, update, uninstall.
For tasks that accept both version and path (status, init, install, update), version is the first positional arg. To pass only a path, leave version empty:
rake 'bootstrap:install[5, public/assets]'
rake 'bootstrap:install[, public/assets]'latest, status, init, install, and update accept version constraints. The constraint finds the latest version within that major or minor:
| Constraint | Resolves to |
|---|---|
5 |
Latest 5.x.y (e.g., 5.3.8) |
5.3 |
Latest 5.3.x (e.g., 5.3.8) |
5.3.5 |
Latest 5.3.x (e.g., 5.3.8) |
4 |
Latest 4.x.y (e.g., 4.6.2) |
- Ruby >= 4.0
- Rails (for automatic Railtie loading) or any Ruby project with Rake
MIT. See LICENSE.txt.