Skip to content

Commit 2f09b25

Browse files
committed
Moved CSS pipeline to postcss
The production setup included all CSS files directly and this resulted in broken links and lots of 404 requests to our server. This new approach compacts everything into a single css file and everything should work better.
1 parent 44c7166 commit 2f09b25

16 files changed

Lines changed: 1189 additions & 8 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@
3636

3737
.claude
3838
CLAUDE.md
39+
40+
/app/assets/builds/*
41+
!/app/assets/builds/.keep
42+
43+
/node_modules

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ENV BUNDLE_WITHOUT="development:test" \
88
NODE_ENV=production
99

1010
RUN apt-get update -qq && \
11-
apt-get install -y --no-install-recommends build-essential libpq-dev git curl && \
11+
apt-get install -y --no-install-recommends build-essential libpq-dev git curl nodejs npm && \
1212
rm -rf /var/lib/apt/lists/*
1313

1414
WORKDIR /app
@@ -18,6 +18,7 @@ RUN bundle install --jobs=4 --retry=3
1818

1919
COPY . .
2020

21+
RUN npm install && npm run build:css
2122
RUN SECRET_KEY_BASE=dummy bundle exec rails assets:precompile
2223

2324
FROM ruby:${RUBY_VERSION}-slim AS final

Dockerfile.dev

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ENV RAILS_ENV=development \
66
BUNDLE_WITHOUT=""
77

88
RUN apt-get update -qq && \
9-
apt-get install -y --no-install-recommends build-essential libpq-dev git curl && \
9+
apt-get install -y --no-install-recommends build-essential libpq-dev git curl nodejs npm && \
1010
rm -rf /var/lib/apt/lists/*
1111

1212
WORKDIR /app
@@ -16,6 +16,9 @@ RUN bundle install --jobs=4 --retry=3
1616

1717
COPY . .
1818

19+
# Install JS dependencies so dev server can run the CSS watcher; actual CSS is rebuilt by bin/dev/foreman.
20+
RUN npm install
21+
1922
EXPOSE 3000
2023

2124
ENTRYPOINT ["./bin/docker-entrypoint"]

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ source "https://rubygems.org"
44
gem "rails", "~> 8.0.2"
55
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
66
gem "propshaft"
7+
gem "cssbundling-rails"
78
# Use postgresql as the database for Active Record
89
gem "pg", "~> 1.1"
910
# PostgreSQL-specific ActiveRecord extensions (UNION, CTE, etc.)

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ GEM
106106
concurrent-ruby (1.3.5)
107107
connection_pool (3.0.2)
108108
crass (1.0.6)
109+
cssbundling-rails (1.4.3)
110+
railties (>= 6.0.0)
109111
date (3.5.0)
110112
debug (1.11.0)
111113
irb (~> 1.10)
@@ -481,6 +483,7 @@ DEPENDENCIES
481483
brakeman
482484
bullet
483485
capybara
486+
cssbundling-rails
484487
debug
485488
factory_bot_rails
486489
faker

Procfile.dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: env RUBY_DEBUG_OPEN=true bin/rails server -b ${HOST:-127.0.0.1} -p ${PORT:-3000}
2+
css: yarn build:css --watch

app/assets/builds/.keep

Whitespace-only changes.

app/assets/stylesheets/application.css renamed to app/assets/stylesheets/application.postcss.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
@import "components/form.css";
1111
@import "components/navigation.css";
1212
@import "components/sidebar.css";
13-
@import "components/search.css";
1413
@import "components/topics.css";
1514
@import "components/avatars.css";
1615
@import "components/participants.css";

app/views/layouts/application.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ html data-theme="light"
2121
var theme = stored || (prefersDark ? 'dark' : 'light');
2222
document.documentElement.dataset.theme = theme;
2323
})();
24-
= stylesheet_link_tag :app, "data-turbo-track": "reload"
24+
= stylesheet_link_tag "application", "data-turbo-track": "reload"
2525
= javascript_importmap_tags
2626
script[src="https://kit.fontawesome.com/92fb6aa8ba.js"]
2727
body

bin/dev

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
#!/usr/bin/env ruby
2-
exec "./bin/rails", "server", *ARGV
1+
#!/usr/bin/env sh
2+
3+
if gem list --no-installed --exact --silent foreman; then
4+
echo "Installing foreman..."
5+
gem install foreman
6+
fi
7+
8+
# Default to port 3000 if not specified
9+
export PORT="${PORT:-3000}"
10+
11+
exec foreman start -f Procfile.dev --env /dev/null "$@"

0 commit comments

Comments
 (0)