Skip to content

Commit

Permalink
poc-websocket: migrate sprockets to esbuild, cssbundling
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-entourage committed Mar 7, 2025
1 parent c640b2d commit 2b81338
Show file tree
Hide file tree
Showing 27 changed files with 572 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ data_export/*.csv

# optional local initializer
config/initializers/local.rb

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

/node_modules
18 changes: 15 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ gem 'rails', '~> 6.1.7.10'
gem 'sass-rails'
gem 'uglifier'
gem 'terser'
gem 'jquery-rails', '~> 4'
gem 'jquery-ui-rails', '~> 5'
gem 'turbolinks', '~> 5'
gem 'coffee-rails', '~> 5'
gem 'active_model_serializers', '~> 0.10'
gem 'handlebars_assets', '~> 0'
Expand Down Expand Up @@ -59,6 +56,21 @@ gem 'chartkick'
gem 'restforce', '~> 7.2.0'
gem 'ffi', '>= 1.15', '< 1.17'

# forces concurrent-ruby version to fix an issue on 1.3.5: https://stackoverflow.com/questions/79360526/uninitialized-constant-activesupportloggerthreadsafelevellogger-nameerror
# this gem declaration should be deleted when using Rails 7
gem 'concurrent-ruby', '1.3.4'

# Pour le support JavaScript moderne
gem 'jsbundling-rails'

# Pour le support CSS moderne
gem 'cssbundling-rails'

# Pour remplacer jQuery UJS si nécessaire
gem 'stimulus-rails'
gem 'turbo-rails' # Remplace turbolinks


group :development, :test do
# gem 'annotate'
# gem 'byebug', '~> 5.0.0'
Expand Down
69 changes: 37 additions & 32 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ GEM
bigdecimal
rexml
crass (1.0.6)
cssbundling-rails (1.4.3)
railties (>= 6.0.0)
csv (3.3.0)
datadog-ci (0.8.3)
msgpack
date (3.4.0)
date (3.4.1)
ddtrace (1.23.3)
datadog-ci (~> 0.8.1)
debase-ruby_core_source (= 3.3.1)
Expand All @@ -173,7 +175,7 @@ GEM
dotenv (= 3.1.4)
railties (>= 6.1)
encryptor (3.0.0)
erubi (1.13.0)
erubi (1.13.1)
event_stream_parser (1.0.0)
execjs (2.10.0)
factory_bot (4.11.1)
Expand Down Expand Up @@ -223,19 +225,15 @@ GEM
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.6)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
icalendar (2.10.3)
ice_cube (~> 0.16)
ostruct
ice_cube (0.17.0)
jmespath (1.6.2)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json (2.7.6)
json-schema (2.8.1)
addressable (>= 2.4)
Expand Down Expand Up @@ -274,7 +272,7 @@ GEM
railties (>= 4)
request_store (~> 1.0)
logstash-event (1.2.02)
loofah (2.23.1)
loofah (2.24.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -291,7 +289,8 @@ GEM
method_source (1.1.0)
mini_magick (5.0.1)
mini_mime (1.1.5)
minitest (5.25.1)
mini_portile2 (2.8.8)
minitest (5.25.4)
momentjs-rails (2.29.4.1)
railties (>= 3.1)
msgpack (1.7.3)
Expand All @@ -305,14 +304,14 @@ GEM
connection_pool (~> 2.2)
net-http2 (0.18.5)
http-2 (~> 0.11)
net-imap (0.5.0)
net-imap (0.5.6)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-smtp (0.5.1)
net-protocol
nexmo (7.2.1)
nexmo-jwt (~> 0.1.1)
Expand All @@ -321,17 +320,18 @@ GEM
nexmo-jwt (0.1.2)
jwt (~> 2)
nio4r (2.7.4)
nokogiri (1.16.7-aarch64-linux)
nokogiri (1.18.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.7-arm-linux)
nokogiri (1.18.3-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.18.3-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.16.7-x86-linux)
nokogiri (1.18.3-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
nokogiri (1.18.3-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.18.3-x86_64-linux-gnu)
racc (~> 1.4)
openssl (3.2.0)
optimist (3.1.0)
Expand All @@ -350,10 +350,10 @@ GEM
puma (6.4.3)
nio4r (~> 2.0)
racc (1.8.1)
rack (2.2.10)
rack (2.2.12)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-test (2.1.0)
rack-test (2.2.0)
rack (>= 1.3)
rack-timeout (0.7.0)
rails (6.1.7.10)
Expand All @@ -379,9 +379,9 @@ GEM
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.2)
loofah (~> 2.21)
nokogiri (~> 1.14)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
rails-observers (0.1.5)
activemodel (>= 4.0)
rails_12factor (0.0.3)
Expand Down Expand Up @@ -507,6 +507,8 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
statsd-ruby (1.5.0)
stimulus-rails (1.3.4)
railties (>= 6.0.0)
store_attribute (1.3.1)
activerecord (>= 6.1)
super_diff (0.13.0)
Expand All @@ -518,12 +520,12 @@ GEM
thor (1.3.2)
tilt (2.4.0)
timecop (0.9.10)
timeout (0.4.2)
timeout (0.4.3)
tinymce-rails (7.5.0)
railties (>= 3.1.1)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
turbo-rails (2.0.12)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uglifier (4.2.1)
Expand All @@ -538,7 +540,8 @@ GEM
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.6)
websocket-driver (0.7.7)
base64
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
Expand Down Expand Up @@ -569,6 +572,8 @@ DEPENDENCIES
bullet
chartkick
coffee-rails (~> 5)
concurrent-ruby (= 1.3.4)
cssbundling-rails
ddtrace (~> 1.0)
dotenv-rails
factory_bot_rails (~> 4)
Expand All @@ -580,8 +585,7 @@ DEPENDENCIES
handlebars_assets (~> 0)
httparty
icalendar
jquery-rails (~> 4)
jquery-ui-rails (~> 5)
jsbundling-rails
json-schema (~> 2.8.1)
kaminari (~> 1)
lograge
Expand All @@ -595,7 +599,7 @@ DEPENDENCIES
puma
rack-attack
rack-timeout
rails (~> 6.0)
rails (~> 6.1.7.10)
rails-controller-testing
rails-observers
rails_12factor
Expand All @@ -621,12 +625,13 @@ DEPENDENCIES
slack-notifier
spring (~> 2.1.0)
spring-commands-rspec
stimulus-rails
store_attribute
super_diff
terser
timecop
tinymce-rails
turbolinks (~> 5)
turbo-rails
uglifier
webmock
whenever
Expand Down
2 changes: 2 additions & 0 deletions Procfile.backoffice-preprod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
web: bundle exec puma -C config/puma.rb
worker_1: bundle exec sidekiq -c ${SIDEKIQ_CONCURRENCY:-2} -q sms -q salesforce -q translation -q mailers -q default -q openai_requests -q broadcast -q denorm
release: ACTIVERECORD_STATEMENT_TIMEOUT=90s bundle exec rake db:migrate
js: yarn build --watch
css: yarn build:css --watch
2 changes: 2 additions & 0 deletions Procfile.backoffice-prod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
web: bundle exec puma -C config/puma.rb
worker_1: bundle exec sidekiq -c ${SIDEKIQ_CONCURRENCY:-2} -q sms -q salesforce -q translation -q mailers -q default -q openai_requests -q broadcast -q denorm
release: ACTIVERECORD_STATEMENT_TIMEOUT=90s bundle exec rake db:migrate
js: yarn build --watch
css: yarn build:css --watch
3 changes: 3 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn build:css --watch
Empty file added app/assets/builds/.keep
Empty file.
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
//= link application.css
// = link_tree ../images
// = link_directory ../stylesheets
//= link_tree ../builds
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Entry point for your Sass build
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ $navbar-inverse-bg: #252525;
$text-color: #555;
$buttons-color: #ef662f;

@import "daterangepicker.css";

@import "daterangepicker";
@import "home";
@import "organization";
@import "sign_in";
Expand All @@ -20,8 +19,7 @@ $buttons-color: #ef662f;
@import "select2-bootstrap";
@import "header";
@import "components";
@import 'layout';

@import "layout";

body.with-navbar { padding-top: $navbar-height; }
.navbar-brand { padding: 5px; }
Expand Down
21 changes: 21 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Entry point for the build script in your package.json
import "@hotwired/turbo-rails"
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const application = Application.start()
const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context))

import "jquery"
import "jquery-ui"
import "select2"
import "moment"
import "daterangepicker"
import "bootstrap-multiselect"
import "chartkick"
// import "Chart.bundle"
import { Chart } from "chart.js"

const customContext = require.context("./custom", true, /\.js$/)
customContext.keys().forEach(customContext)
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.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAOyNFh41PIKiNW9WYWrOH67c-wY1zVRVY&libraries=drawing,places,visualization"></script>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag "application", "data-turbo-track" => "reload" %>
<%= javascript_include_tag "application", "data-turbo-track" => "reload", defer: true %>
<%= csrf_meta_tags %>
<%= favicon_link_tag 'favicon.ico', type: 'image/x-icon' %>
<%= favicon_link_tag 'favicon.ico', rel: 'apple-touch-icon', type: 'image/x-icon' %>
Expand Down
11 changes: 11 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

if gem list --no-installed --exact --silent foreman; then
echo "Installing foreman..."
gem install foreman
fi

# Default to port 3000 if not specified
export PORT="${PORT:-3000}"

exec foreman start -f Procfile.dev --env /dev/null "$@"
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "app",
"private": true,
"scripts": {
"build": "esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets",
"build:css": "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
},
"devDependencies": {
"esbuild": "^0.25.0"
},
"dependencies": {
"@hotwired/turbo-rails": "^8.0.13",
"bootstrap-multiselect": "^1.1.0",
"chart.js": "^4.4.8",
"chartkick": "^5.0.1",
"daterangepicker": "^3.1.0",
"jquery": "^3.7.1",
"jquery-ui": "^1.14.1",
"moment": "^2.30.1",
"sass": "^1.85.1",
"select2": "^4.1.0-rc.0",
"stimulus": "^3.2.2"
}
}
Loading

0 comments on commit 2b81338

Please sign in to comment.