introduce importmaps (#983)

* introduce importmaps

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 <philipprothmann@posteo.de>
Co-authored-by: FGU <fgu@pragma-shift.net>

* fix: rubocop violations

---------

Co-authored-by: FGU <fgu@pragma-shift.net>
This commit is contained in:
Philipp Rothmann 2023-06-14 13:29:31 +02:00 committed by GitHub
parent a8b2f387db
commit 026c3a6285
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 3 deletions

View file

@ -124,4 +124,5 @@ group :test do
gem 'rswag-specs' gem 'rswag-specs'
end end
gem "importmap-rails", "~> 1.1"
gem "terser", "~> 1.1" gem "terser", "~> 1.1"

View file

@ -254,6 +254,9 @@ GEM
i18n-spec (0.6.0) i18n-spec (0.6.0)
iso iso
ice_cube (0.16.4) ice_cube (0.16.4)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
inherited_resources (1.13.1) inherited_resources (1.13.1)
actionpack (>= 5.2, < 7.1) actionpack (>= 5.2, < 7.1)
has_scope (~> 0.6) has_scope (~> 0.6)
@ -624,6 +627,7 @@ DEPENDENCIES
i18n-js (~> 3.0.0.rc8) i18n-js (~> 3.0.0.rc8)
i18n-spec i18n-spec
ice_cube ice_cube
importmap-rails (~> 1.1)
inherited_resources inherited_resources
jquery-rails jquery-rails
kaminari kaminari

View file

@ -0,0 +1 @@
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails

View file

@ -8,10 +8,10 @@
= csrf_meta_tags = csrf_meta_tags
= stylesheet_link_tag "application", :media => "all" = stylesheet_link_tag "application", :media => "all"
//%link(href="images/favicon.ico" rel="shortcut icon") //%link(href="images/favicon.ico" rel="shortcut icon")
= yield(:head) = yield(:head)
= foodcoop_css_tag = foodcoop_css_tag
%body %body
= yield = yield
@ -19,7 +19,9 @@
Javascripts Javascripts
\================================================== \==================================================
/ Placed at the end of the document so the pages load faster / 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 :javascript
I18n.defaultLocale = "#{I18n.default_locale}"; I18n.defaultLocale = "#{I18n.default_locale}";
I18n.locale = "#{I18n.locale}"; I18n.locale = "#{I18n.locale}";

4
bin/importmap Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative "../config/application"
require "importmap/commands"

2
config/importmap.rb Normal file
View file

@ -0,0 +1,2 @@
# Pin npm packages by running ./bin/importmap
pin "application", preload: true

View file

@ -9,4 +9,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets # application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added. # 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]

0
vendor/javascript/.keep vendored Normal file
View file