Search code examples
javascriptruby-on-railsrubystylesheetassets

How to add a frontend asset from a git repo/npm project to a rails project


I want to contribute to an open source project written in rails with some frontend web stuff, that depends on an asset, which I have on an external git repository. So I would like to add the asset dependency from the git link and just add my code to the frontend.

I do not know much about rails, especially asset managements, but that the css and js files are all in the manifest files, and come seemingly from some ruby gems, which include the css and js assets then.

So is there a good way to add an asset to my rails manifest file/assets without having it as a ruby gem, just from a git repo?

Thank you so much for help and pardon my rails illiteracy :S


Solution

  • I managed to add just a .gemspec to my npm repo, move my js and css to the vendor/assets folder, all in a dedicated "gemfile branch"

    Gem::Specification.new do |s|
      s.name        = 'asset-name'
      s.version     = '0.0.0'
      s.date        = '2020-05-30'
      s.summary     = "What my package does."
      s.description = ""
      s.files       = [
            "vendor/assets/javascripts/app.min.js",
            "vendor/assets/stylesheets/app.css"
      ]
      s.license       = 'MIT'
    end
    

    and then added the repo with its branch to the rail projectsGemfile` like this:

    gem "asset-name", :git => "git://github.com/user/repo.git", :branch => "ruby-gem"