|
30 | 30 | task default: %i[test rubocop] |
31 | 31 |
|
32 | 32 | namespace :assets do |
33 | | - desc "Compiles all assets" |
| 33 | + desc "Compiles all assets using esbuild" |
34 | 34 | task :compile do |
35 | 35 | puts "Compiling assets" |
36 | | - require "sprockets" |
37 | | - require "sprockets/sass_processor" |
38 | 36 |
|
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) |
41 | 53 | 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") |
54 | 54 | end |
55 | 55 | end |
0 commit comments