Skip to content

Instantly share code, notes, and snippets.

@chloerei
Created November 5, 2023 04:54
Show Gist options
  • Save chloerei/e01d6d59993d14c83597a55532b89c5b to your computer and use it in GitHub Desktop.
Save chloerei/e01d6d59993d14c83597a55532b89c5b to your computer and use it in GitHub Desktop.
require "importmap/npm"
require "importmap/packager"
namespace :importmap do
desc "Download"
task :download do
npm = Importmap::Npm.new
packager = Importmap::Packager.new
packages = npm.packages_with_versions.map { |item| item.join("@") }
imports = packager.import(packages)
imports.each do |package, url|
puts %(Pinning "#{package}" to #{packager.vendor_path}/#{package}.js via download from #{url})
packager.download(package, url)
end
end
end
Rake::Task["assets:precompile"].enhance(["importmap:download"])
@chloerei
Copy link
Author

chloerei commented Nov 5, 2023

Add /vendor/javascript to .gitignore and download assets when running asset precompile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment