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>
pull/50/head
Philipp Rothmann 2023-01-27 11:16:53 +01:00
parent 82d4ff0284
commit 666e7934a6
9 changed files with 19 additions and 4 deletions

View File

@ -126,3 +126,5 @@ group :test do
gem 'rswag-specs'
gem 'hashie', '~> 3.4.6', require: false # https://github.com/westfieldlabs/apivore/issues/114
end
gem "importmap-rails", "~> 1.1"

View File

@ -255,6 +255,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)
@ -628,6 +631,7 @@ DEPENDENCIES
i18n-js (~> 3.0.0.rc8)
i18n-spec
ice_cube
importmap-rails (~> 1.1)
inherited_resources
jquery-rails
kaminari
@ -686,4 +690,4 @@ DEPENDENCIES
whenever
BUNDLED WITH
2.4.3
2.4.5

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
= stylesheet_link_tag "application", :media => "all"
//%link(href="images/favicon.ico" rel="shortcut icon")
= yield(:head)
= foodcoop_css_tag
%body
= yield
@ -19,7 +19,9 @@
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}";

4
bin/importmap 100755
View File

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

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.
# 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 )

0
vendor/javascript/.keep vendored 100644
View File