Skip to content
0:00 / 0:00

#rails#importmap#webpack

Alpha preview: Modern JavaScript in Rails 7 without Webpack

David Heinemeier Hansson

58K subscribers • 1 video on Hallway

YouTube
  • Recommended by 1 person: 1 on Stack Overflow and its sister sites.
  • Presented by David Heinemeier Hansson, creator of Ruby on Rails
  • Linked in the descriptionrails/rails
  • May be out of date. The tools, versions or practices it shows have likely moved on.
  • An opinion. It argues one side of a question engineers disagree on.

Intermediate. Assumes working knowledge.

62K views5 years ago1 recommendation

Web developmentVue, Svelte, Angular and othersRubyWeb performance

David Heinemeier Hansson demonstrates how to use modern JavaScript in Rails 7 using import maps instead of Webpack.

Modern web apps without JavaScript bundling or transpiling: world.hey.com/dhh/modern-web-apps-without-javascript-bundlin… Rails 7 minus Webpack plus importmap PR: github.com/rails/rails/pull/42999

Why it's here

1 person recommends this

What people say. Recommended for understanding how to structure page-specific JavaScript in Rails 7 using import maps.

Moments people linked to

Zackon Stack Overflow • Recommends

On “Where to place Javascript used in one page only in Rails 7 with importmap”

As @Azrklm points out, the answer is contained in this video link to this video beginning at time 21:38. Suppose we have some JavaScript that we want to run only on a view called FancyView . Here are the steps Place the code unique to FancyView in its own file, say FancyView.js (and remove it from application.js , if necessary). Add a line for FancyView.js to the importmap: pin "FancyView" Add the line <%= yield :head %> to application.html.erb`. (This tells Rails that individual views/layouts may want to add additional information to the web page's head.) <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> <%# This loads application.js %>…
22View the answer