All threads / How do I add minified JS files to the Rails Webpacker

Ask A Question

Notifications

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
Calendar
<%= 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
Calendar
<%= 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?

Thanks

Arjun

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

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.