Skip to content

Commit

Permalink
Replace webpacker with jsbundling rails (#326)
Browse files Browse the repository at this point in the history
**This PR:**
- Replaces webpacker with jsbundling-rails since it is not supported by Rails 7
- Updates the node version to the [latest](https://nodejs.org/en/about/previous-releases#nodejs-releases), `22.6.0`
- Updates the Postgres image for CI

**Guide:** [Upgrading to Rails 7: Moving away from Webpacker ](https://thoughtbot.com/blog/upgrading-to-rails7-moving-away-from-webpacker)

Co-authored-by: Sally Hall <[email protected]>
  • Loading branch information
louis-antonopoulos and sallyhall authored Aug 23, 2024
1 parent 747d202 commit dbcf9f5
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 7,761 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ jobs:
RAILS_ENV: test
PGHOST: 127.0.0.1
PGUSER: root
- image: circleci/postgres:11.4-alpine
- image: cimg/postgres:12.20
environment:
POSTGRES_DB: example_app_test
POSTGRES_USER: root

steps:
- checkout

- run:
name: Create symlink for package.json
command: ln -s ./spec/example_app/package.json ./package.json
- restore_cache:
keys:
- yuriita-bundle-{{ checksum "Gemfile.lock" }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ spec/example_app/.env
spec/example_app/log/*
spec/example_app/tmp/*
spec/example_app/public/assets
spec/example_app/node_modules
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ruby 3.1.6
nodejs 12.16.1
nodejs 22.6.0
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ gem "bootsnap", ">= 1.4.4", require: false
gem "bourbon"
gem "commonmarker", "< 1.0"
gem "github-markup", require: "github/markup"
gem "jsbundling-rails"
gem "pg", ">= 0.18", "< 2.0"
gem "puma", "~> 6.0"
gem "sass-rails", ">= 6"
gem "sentry-raven"
gem "themoviedb-api"
gem "webpacker", '~> 5'

group :test, :development do
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
Expand Down
12 changes: 3 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ GEM
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -188,8 +190,6 @@ GEM
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.7)
rack-proxy (0.7.7)
rack
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -284,7 +284,6 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
semantic_range (3.0.0)
sentry-raven (3.1.2)
faraday (>= 1.0)
sprockets (4.2.1)
Expand Down Expand Up @@ -314,11 +313,6 @@ GEM
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
webpacker (5.4.4)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
webrick (1.8.1)
websocket (1.2.11)
websocket-driver (0.7.6)
Expand All @@ -341,6 +335,7 @@ DEPENDENCIES
dotenv-rails
factory_bot_rails
github-markup
jsbundling-rails
listen (>= 3.0.5)
pg (>= 0.18, < 2.0)
pry-rails
Expand All @@ -355,7 +350,6 @@ DEPENDENCIES
themoviedb-api
web-console (>= 3.3.0)
webdrivers
webpacker (~> 5)
yuri-ita!

RUBY VERSION
Expand Down
18 changes: 0 additions & 18 deletions bin/webpack

This file was deleted.

18 changes: 0 additions & 18 deletions bin/webpack-dev-server

This file was deleted.

3 changes: 3 additions & 0 deletions spec/example_app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
/yarn-error.log
yarn-debug.log*
.yarn-integrity

/app/assets/builds/*
!/app/assets/builds/.keep
Empty file.
1 change: 1 addition & 0 deletions spec/example_app/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
//= link_directory ../stylesheets .css
//= link_tree ../builds
1 change: 1 addition & 0 deletions spec/example_app/app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Entry point for the build script in your package.json
4 changes: 2 additions & 2 deletions spec/example_app/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_pack_tag 'application' %>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
</head>

<body>
Expand Down
4 changes: 2 additions & 2 deletions spec/example_app/app/views/layouts/documentation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag 'documentation', media: 'all' %>
<%= javascript_pack_tag 'application' %>
<%= stylesheet_link_tag "documentation", media: "all" %>
<%= javascript_include_tag "application" %>
</head>

<body data-controller="syntax-highlight">
Expand Down
18 changes: 0 additions & 18 deletions spec/example_app/bin/webpack

This file was deleted.

18 changes: 0 additions & 18 deletions spec/example_app/bin/webpack-dev-server

This file was deleted.

2 changes: 0 additions & 2 deletions spec/example_app/config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Add Yarn node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join('node_modules')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
Expand Down
5 changes: 0 additions & 5 deletions spec/example_app/config/webpack/development.js

This file was deleted.

3 changes: 0 additions & 3 deletions spec/example_app/config/webpack/environment.js

This file was deleted.

5 changes: 0 additions & 5 deletions spec/example_app/config/webpack/production.js

This file was deleted.

5 changes: 0 additions & 5 deletions spec/example_app/config/webpack/test.js

This file was deleted.

24 changes: 24 additions & 0 deletions spec/example_app/config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const mode = process.env.NODE_ENV === "development" ? "development" : "production";
const path = require("path")
const webpack = require("webpack")

module.exports = {
mode,
entry: {
application: "./spec/example_app/app/javascript/application.js"
},
optimization: {
moduleIds: "deterministic",
},
output: {
filename: "[name].js",
sourceMapFilename: "[file].map",
chunkFormat: "module",
path: path.resolve(__dirname, "..", "..", "app/assets/builds"),
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
]
}
92 changes: 0 additions & 92 deletions spec/example_app/config/webpacker.yml

This file was deleted.

8 changes: 5 additions & 3 deletions spec/example_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"license": "MIT",
"dependencies": {
"@rails/ujs": "^7.0.4",
"@rails/webpacker": "5.4.4",
"highlight.js": "^11.7.0",
"stimulus": "^3.2.1"
},
"devDependencies": {
"@webpack-cli/serve": "^2.0.5",
"webpack-dev-server": "^5.0.4"
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
},
"scripts": {
"build": "webpack --config spec/example_app/config/webpack/webpack.config.js"
}
}
Loading

0 comments on commit dbcf9f5

Please sign in to comment.