Relevant for more complex applications where you don't want to lose speed! For your projects the general import in applications.js will be enough :)
- Add the yield(:after_js) to your layout
`# application.html.erb
<%= yield %> <%= javascript_include_tag 'application' %> <%= javascript_pack_tag 'application' %> <%= yield(:after_js) %> `-
Add the content_for in the chosen view
#views/flats/index.html.erb <%= content_for(:after_js) do %> <%= javascript_pack_tag "mapbox.js" %> <% end %>
-
Create a mapbox.js file in the app/javascript/packs folder where you will import all the logic from your plugins/init_mapbox.js
-
Remove the imports for mapbox from main app/javascript/packs/application.js file which is called on every page oy your app