Skip to content

Commit

Permalink
Chore: Move css processing to cssbundling-rails
Browse files Browse the repository at this point in the history
Because:
Cssbundling-rails is the default way to handle css through the asset
pipeline in Rails.

This commit:

- Add cssbundling-rails gem
- update gitignore to ignore asdf local ruby version file
- stop sprockets minifying css with sass
- remove unused application_stylesheet scss file
- delete webpacker application css file
- move stylesheets from javascript to assets directory
- Update active_admin scss file to import from npm packages
- run cssbundling install command
- use cssnano to compress postcss content
- update stylesheet link tag to import application file

Update package.json
  • Loading branch information
CouchofTomato committed Sep 11, 2023
1 parent 4393e5c commit f8c0d4f
Show file tree
Hide file tree
Showing 23 changed files with 536 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ yarn-debug.log*
# Vim Swap File
.swp
.vscode/settings.json

/app/assets/builds/*
!/app/assets/builds/.keep

# Ruby tool versions
.tool-versions
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem 'active_material', '~> 1.5'
gem 'barnes', '~> 0.0'
gem 'bootsnap', '~> 1.16', require: false
gem 'classy-yaml', '~> 0.8'
gem 'cssbundling-rails', '~> 1.2'
gem 'debug', '~> 1.7'
gem 'devise', '~> 4.9'
gem 'discard', '~> 1.2'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ GEM
crass (1.0.6)
css_parser (1.14.0)
addressable
cssbundling-rails (1.2.0)
railties (>= 6.0.0)
cuprite (0.14.3)
capybara (~> 3.0)
ferrum (~> 0.13.0)
Expand Down Expand Up @@ -584,6 +586,7 @@ DEPENDENCIES
capybara (~> 3.39)
classy-yaml (~> 0.8)
climate_control (~> 1.2)
cssbundling-rails (~> 1.2)
cuprite (~> 0.14)
debug (~> 1.7)
devise (~> 4.9)
Expand Down
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
web: bundle exec puma -C config/puma_development.rb -p 3000
worker: bundle exec sidekiq
webpack: bin/webpacker-dev-server
css: yarn build:css --watch
Empty file added app/assets/builds/.keep
Empty file.
2 changes: 1 addition & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//= link_tree ../images
//= link active_admin.js
//= link application_stylesheet.css
//= link_tree ../builds
7 changes: 3 additions & 4 deletions app/assets/stylesheets/active_admin.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
$am-theme-primary: #cc9543;
$am-theme-accent: #4a4a4a;

@import 'activeadmin_addons/all';
@import 'activeadmin_addons/material';
@import 'activeadmin_addons/src/stylesheets/all';

@import "active_admin/mixins";
@import "active_material";
@import "@activeadmin/activeadmin/src/scss/mixins";
@import "active_material/src/stylesheets/active_material";

input[type="submit"] {
&:disabled {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* turning off base styles for now as they override heading sizes */
/* Entry point for your PostCSS build */
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Expand All @@ -11,4 +11,4 @@
@import './stylesheets/prism-theme.css';
@import './stylesheets/pagy.css';
@import './stylesheets/animations.css';
@import './stylesheets/static-pages.css';
@import './stylesheets/static-pages.css';
11 changes: 0 additions & 11 deletions app/assets/stylesheets/application_stylesheet.scss

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">

<%= stylesheet_link_tag 'application_stylesheet', media: 'all', 'data-turbo-track': 'reload' %>
<%= stylesheet_pack_tag 'application', 'data-turbo-track': 'reload' %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbo-track': 'reload' %>

<%= javascript_pack_tag 'application', 'data-turbo-track': 'reload', defer: true %>
<%= render 'shared/analytics' %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/errors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<%= content_for(:title) || 'Your Career in Web Development Starts Here | The Odin Project' %>
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= stylesheet_link_tag 'application_stylesheet', media: 'all' %>
<%= stylesheet_pack_tag 'application' %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_pack_tag 'application', 'data-turbo-track': 'reload', defer: true %>
</head>
<body class="text-center h-screen m-0">
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class Application < Rails::Application
# the framework and any gems in your application.
config.exceptions_app = routes
config.middleware.insert_after ActionDispatch::Static, Rack::Deflater
config.assets.css_compressor = nil
end
end
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
"version": "1.0.0",
"private": true,
"scripts": {
"eslint": "eslint --max-warnings 0 './app/javascript/**/*.js' './app/components/**/*.js'"
"eslint": "eslint --max-warnings 0 './app/javascript/**/*.js' './app/components/**/*.js'",
"build:css": "npm-run-all --parallel \"build:css:* {@}\" --",
"build:css:application": "postcss ./app/assets/stylesheets/application.postcss.css -o ./app/assets/builds/application.css",
"build:css:active_admin": "sass ./app/assets/stylesheets/active_admin.scss ./app/assets/builds/active_admin.css --no-source-map --load-path=node_modules --style=compressed"
},
"dependencies": {
"@activeadmin/activeadmin": "^3.0.0",
"@babel/core": "7",
"@babel/eslint-parser": "^7.21.8",
"@babel/plugin-proposal-private-methods": "^7.18.6",
Expand All @@ -22,7 +26,9 @@
"@stimulus/polyfills": "^2.0.0",
"@tailwindcss/forms": "^0.5.6",
"@tailwindcss/typography": "^0.5.9",
"autoprefixer": "^10",
"active_material": "^2.0.2",
"activeadmin_addons": "^2.0.0-beta.2",
"autoprefixer": "^10.4.15",
"axios": "^1.3.5",
"babel-loader": "9",
"babel-plugin-prismjs": "^2.1.0",
Expand All @@ -32,14 +38,17 @@
"css-loader": "^6.7.3",
"css-minimizer-webpack-plugin": "^5.0.1",
"debounce": "^1.2.1",
"cssnano": "^6.0.1",
"el-transition": "^0.0.7",
"hint.css": "^2.7.0",
"js-base64": "^3.7.5",
"lodash": "^4.17.21",
"mermaid": "^9.4.3",
"mini-css-extract-plugin": "^2.7.6",
"npm-run-all": "^4.1.5",
"pnp-webpack-plugin": "1",
"postcss": "^8.4.27",
"postcss": "^8.4.28",
"postcss-cli": "^10.1.0",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-import": "^15.1.0",
"postcss-loader": "^7.3.3",
Expand Down
3 changes: 3 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module.exports = {
flexbox: 'no-2009'
},
stage: 3
}),
require('cssnano')({
preset: 'default'
})
]
}
Loading

0 comments on commit f8c0d4f

Please sign in to comment.