Skip to content

Commit e339879

Browse files
committed
Replace Sprockets with esbuild, convert JS to TypeScript
* Remove Sprockets, Uglifier, and sass gem dependencies * esbuild compiles TypeScript directly and minifies in 2ms
1 parent cab5e5f commit e339879

8 files changed

Lines changed: 522 additions & 533 deletions

File tree

Gemfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ group :development do
2424
gem "rubocop-minitest"
2525
gem "rubocop-performance"
2626
gem "rubocop-rake"
27-
gem "sass"
28-
gem "sprockets"
29-
gem "uglifier"
3027
end
3128

3229
gem "logger" if RUBY_VERSION >= "3.4"

Gemfile.lock

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: https://github.com/simplecov-ruby/simplecov
3-
revision: 3d8d723874ff14b06f30dee5d1453f9acc92fdf9
3+
revision: 7245d3a1292f4feb17c8876c5357e4034b0595a4
44
specs:
55
simplecov (0.22.0)
66
docile (~> 1.1)
@@ -16,18 +16,14 @@ GEM
1616
remote: https://rubygems.org/
1717
specs:
1818
ast (2.4.3)
19-
concurrent-ruby (1.3.6)
2019
docile (1.4.1)
2120
drb (2.2.3)
22-
execjs (2.10.0)
23-
ffi (1.17.4-arm64-darwin)
24-
ffi (1.17.4-java)
2521
json (2.19.3)
2622
json (2.19.3-java)
2723
language_server-protocol (3.17.0.5)
2824
lint_roller (1.1.0)
2925
logger (1.7.0)
30-
minitest (6.0.2)
26+
minitest (6.0.3)
3127
drb (~> 2.0)
3228
prism (~> 1.5)
3329
nokogiri (1.19.2-arm64-darwin)
@@ -41,12 +37,8 @@ GEM
4137
prism (1.9.0)
4238
racc (1.8.1)
4339
racc (1.8.1-java)
44-
rack (3.2.5)
4540
rainbow (3.1.1)
4641
rake (13.3.1)
47-
rb-fsevent (0.11.2)
48-
rb-inotify (0.11.1)
49-
ffi (~> 1.0)
5042
regexp_parser (2.11.3)
5143
rubocop (1.86.0)
5244
json (~> 2.3)
@@ -74,18 +66,7 @@ GEM
7466
lint_roller (~> 1.1)
7567
rubocop (>= 1.72.1)
7668
ruby-progressbar (1.13.0)
77-
sass (3.7.4)
78-
sass-listen (~> 4.0.0)
79-
sass-listen (4.0.0)
80-
rb-fsevent (~> 0.9, >= 0.9.4)
81-
rb-inotify (~> 0.9, >= 0.9.7)
8269
simplecov_json_formatter (0.1.4)
83-
sprockets (4.2.2)
84-
concurrent-ruby (~> 1.0)
85-
logger
86-
rack (>= 2.2.4, < 4)
87-
uglifier (4.2.1)
88-
execjs (>= 0.3.0, < 3)
8970
unicode-display_width (3.2.0)
9071
unicode-emoji (~> 4.1)
9172
unicode-emoji (4.2.0)
@@ -104,11 +85,8 @@ DEPENDENCIES
10485
rubocop-minitest
10586
rubocop-performance
10687
rubocop-rake
107-
sass
10888
simplecov!
10989
simplecov-html!
110-
sprockets
111-
uglifier
11290

11391
BUNDLED WITH
11492
4.0.9

Rakefile

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,26 @@ end
3030
task default: %i[test rubocop]
3131

3232
namespace :assets do
33-
desc "Compiles all assets"
33+
desc "Compiles all assets using esbuild"
3434
task :compile do
3535
puts "Compiling assets"
36-
require "sprockets"
37-
require "sprockets/sass_processor"
3836

39-
Sprockets.register_processor("text/css") do |input|
40-
{data: input[:data].gsub(/(?<!-|_)url\(['"]?(.+?)['"]?\)/) { "asset-data-url(\"#{Regexp.last_match(1)}\")" }}
37+
# JS: esbuild compiles TypeScript directly, then we concatenate with highlight.js and minify
38+
sh "esbuild src/app.ts --bundle --minify --target=es2015 " \
39+
"--banner:js=\"$(cat assets/javascripts/plugins/highlight.pack.js)\" " \
40+
"--outfile=public/application.js"
41+
42+
# CSS: concatenate in order and minify
43+
css = %w[
44+
assets/stylesheets/reset.css
45+
assets/stylesheets/plugins/highlight.css
46+
assets/stylesheets/screen.css
47+
].map { |f| File.read(f) }.join("\n")
48+
49+
IO.popen(%w[esbuild --minify --loader=css], "r+") do |io|
50+
io.write(css)
51+
io.close_write
52+
File.write("public/application.css", io.read)
4153
end
42-
43-
Sprockets.register_processor "text/css", Sprockets::ScssProcessor
44-
45-
assets = Sprockets::Environment.new do |env|
46-
env.append_path "assets/javascripts"
47-
env.append_path "assets/stylesheets"
48-
env.append_path "public"
49-
env.js_compressor = :uglify
50-
env.css_compressor = :scss
51-
end
52-
assets["application.js"].write_to("public/application.js")
53-
assets["application.css"].write_to("public/application.css")
5454
end
5555
end

0 commit comments

Comments
 (0)