Ask A Question


You’re not receiving notifications from this thread.

How do I add minified JS files to the Rails Webpacker

Arjun Rajkumar asked in Rails

I am trying to add min.js files - and getting an error.

This works while adding a normal .js file:

- app/javascript/packs/calendar.js
alert('Calendar loaded')

-# app/views/calendars/index.html.erb
<%= javascript_pack_tag 'calendar' %>

The above code works. But when I try to add a min.js file it gives an error.
-# app/views/calendars/index.html.erb
<%= javascript_pack_tag 'calendar' %>
<%= javascript_pack_tag 'something.min' %>

Can anyone share what the process is for adding min.js files to view via Rails Webpacker?




ALso - I have added 'something.min' to the javascript/packs/something.min.js


I made a stupid mistake!

Can call minified JS files also with the same way.
So, instead of '<%= javascript_pack_tag 'something.min' %>' like I did before - I just have to use '<%= javascript_pack_tag 'something' %>' - and it runs.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 80,973+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.