This document outlines the steps taken to upgrade this Middleman project from Ruby 2.7.8 to Ruby 3.2.2 and fix CSS compilation issues.
cd /Users/kurt/repos/new/api-docs
echo "3.2.2" > .ruby-versionrm -rf Gemfile.lock vendor/bundle .bundleUpdate the Gemfile with Ruby 3.2+ compatible versions:
source 'https://rubygems.org'
ruby '>=2.7.0'
# Middleman - using 4.3.x for better compatibility
gem 'middleman', '~> 4.3.0'
gem 'middleman-syntax', '~> 3.2.0'
gem 'middleman-autoprefixer', '~> 2.10.0'
gem 'middleman-sprockets', '~> 4.1.0'
gem 'rouge', '~> 3.26'
gem 'redcarpet', '~> 3.5.0'
gem 'nokogiri', '~> 1.13.0'
gem 'haml', '~> 5.2' # Pin to Haml 5.x for middleman-syntax compatibility
gem 'execjs'
gem 'mini_racer', platforms: :ruby
# Standard libraries removed from Ruby 3.4+
gem 'mutex_m'
gem 'webrick'
gem 'base64'
gem 'bigdecimal'bundle installEdit config.rb:
Remove this line:
renderer: UniqueHeadCounterFrom the markdown configuration block, so it looks like:
# Markdown
set :markdown_engine, :redcarpet
set :markdown,
fenced_code_blocks: true,
smartypants: true,
disable_indented_code_blocks: true,
prettify: true,
tables: true,
with_toc_data: true,
no_intra_emphasis: trueIn config.rb, configure Sprockets to only process JavaScript files:
# Configure Sprockets to handle JS only, not CSS
activate :sprockets do |c|
c.supported_output_extensions = ['.js']
endWhy this works:
- Sprockets handles JavaScript bundling (needed for navigation to work)
- Middleman's native Sass compiler handles CSS (properly inlines all
@importstatements) - Without this, Sprockets tries to handle CSS but doesn't inline
@importstatements, causing 404 errors
In config.rb, comment out autoprefixer (causes CSS syntax errors with Ruby 3.2):
# Autoprefixer disabled - causes CSS syntax errors with Ruby 3.2
# activate :autoprefixer do |config|
# config.browsers = ['last 2 version', 'Firefox ESR']
# config.cascade = false
# config.inline = true
# endIn source/stylesheets/screen.css.scss and source/stylesheets/print.css.scss, change single quotes to double quotes for imports:
@charset "utf-8";
@import "normalize";
@import "variables";
@import "icon-font";Add a comment at the top of source/stylesheets/_normalize.scss to force Sass to inline it:
/*! normalize.css v3.0.2 | MIT License | git.io/normalize */
// Force Sass to inline this file instead of emitting a runtime @importbundle exec middleman server- UniqueHeadCounter renderer - Incompatible with Ruby 3.2's Redcarpet initialization
- Sprockets - Was not properly inlining Sass
@importstatements, causing 404 errors - Autoprefixer - Causing CSS syntax errors with Ruby 3.2
- Sass compilation - Switched from Sprockets to Middleman's native Sass compiler
- Native Sass compilation (without Sprockets) properly inlines all
@importstatements - The CSS is fully compiled into single files (
screen.cssandprint.css) - All partials (
_normalize.scss,_variables.scss,_icon-font.scss) are expanded inline - Font URLs are properly resolved to
/fonts/paths
.ruby-version- Changed to3.2.2Gemfile- Updated gem versions for Ruby 3.2 compatibilityconfig.rb- Removed UniqueHeadCounter, disabled Sprockets and Autoprefixersource/stylesheets/screen.css.scss- Changed imports to double quotessource/stylesheets/print.css.scss- Changed imports to double quotessource/stylesheets/_normalize.scss- Added inline comment.gitignore- Added/gems/,/extensions/,/vendor/bundle/
Make sure .gitignore includes:
/gems/
/extensions/
/vendor/bundle/
This prevents large binary files from being committed.
bin/andspecifications/directories are safe to commit (small text files)- Gems are now installed to system location (
~/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/) - Use
bundle exec middleman serverto run (not justmiddleman server)