Search code examples
ruby-on-rails-6webpacker

Rails 6: conditional link asset in manifest.js


In my Rails 6 application that uses grape_swagger_rails, the Swagger UI should only be available in specific environments.

But their Readme asks to to modify manifest.js which is applied across all environments. I tried renaming it to manifest.js.erb and using Ruby code to make the link statement conditional but as it turns out, ERB is not supported there.

Is there a way to conditionally include assets in the manifest based on the Rails environment?


Solution

  • I use two manifest files and include them conditionally like shown below:

      <% if X %>
      <link rel="manifest" href="/manifestX.json">
      <% else %>
      <link rel="manifest" href="/manifest.json">
      <% end %>