Skip to content

Commit a42863f

Browse files
committed
Add rake task to vendor guide javascript
The Rails guides were migrated from Turbolinks to Turbo in 0f6575a The PR discussion explains that the file was grabbed from unpkg, and a decision was made to not run it through a minifier. This commit adds a rake task to automate the process of grabbing the turbo js file using Importmap::Packager, which is what importmap-rails uses for `bin/importmap pin --download`. The extra Importmap module definition is necessary because the Importmap::Packager file uses the shorthand module syntax, meaning that an error is thrown if the Importmap module is not previously defined. `require "importmap-rails"` would normally define this module, but one of its dependent requires will not load outside of a Rails application. The turbo.css file was removed as it appears to be leftover from Turbolinks and Turbo does not provide any css files in its dist.
1 parent f838a74 commit a42863f

File tree

5 files changed

+209
-124
lines changed

5 files changed

+209
-124
lines changed

guides/Rakefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ namespace :guides do
3030
ruby "w3c_validator.rb"
3131
end
3232

33+
task :vendor_javascript do
34+
module Importmap; end
35+
require "importmap/packager"
36+
37+
packager = Importmap::Packager.new(vendor_path: "assets/javascripts")
38+
imports = packager.import("@hotwired/turbo", from: "unpkg")
39+
imports.each do |package, url|
40+
umd_url = url.gsub("esm.js", "umd.js")
41+
puts %(Vendoring "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{umd_url})
42+
packager.download(package, umd_url)
43+
end
44+
end
45+
3346
desc "Show help"
3447
task :help do
3548
puts <<HELP

0 commit comments

Comments
 (0)