Skip to content

Commit

Permalink
introduce importmaps
Browse files Browse the repository at this point in the history
This commit introduces importmaps. They allow to use modern javacript ESM within rails without webpack, yarn etc.
see https://github.com/rails/importmap-rails for more details.

Co-authored-by: Philipp Rothmann <[email protected]>
Co-authored-by: FGU <[email protected]>
  • Loading branch information
yksflip and flooguu committed Jun 9, 2023
1 parent 8b0e03f commit 51b5c10
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ group :test do
end

gem "terser", "~> 1.1"
gem "importmap-rails", "~> 1.1"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ GEM
i18n-spec (0.6.0)
iso
ice_cube (0.16.4)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
inherited_resources (1.13.1)
actionpack (>= 5.2, < 7.1)
has_scope (~> 0.6)
Expand Down Expand Up @@ -623,6 +626,7 @@ DEPENDENCIES
i18n-js (~> 3.0.0.rc8)
i18n-spec
ice_cube
importmap-rails (~> 1.1)
inherited_resources
jquery-rails
kaminari
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
6 changes: 4 additions & 2 deletions app/views/layouts/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
= csrf_meta_tags
= stylesheet_link_tag "application", :media => "all"
//%link(href="images/favicon.ico" rel="shortcut icon")
= yield(:head)
= foodcoop_css_tag


%body
= yield

/
Javascripts
\==================================================
/ Placed at the end of the document so the pages load faster
= javascript_include_tag "application"
= javascript_importmap_tags
= javascript_include_tag "application_legacy"

:javascript
I18n.defaultLocale = "#{I18n.default_locale}";
I18n.locale = "#{I18n.locale}";
Expand Down
4 changes: 4 additions & 0 deletions bin/importmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby

require_relative "../config/application"
require "importmap/commands"
2 changes: 2 additions & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
2 changes: 1 addition & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += %w( application_legacy.js jquery.min.js )
Empty file added vendor/javascript/.keep
Empty file.

0 comments on commit 51b5c10

Please sign in to comment.