-
Notifications
You must be signed in to change notification settings - Fork 124
Allow multiple importmaps in config/importmaps/ #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b97ef07
d490b0c
6f5aa5f
91c7feb
61cfb3a
671031a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,14 @@ | ||||||||||||
module Importmap::ImportmapTagsHelper | ||||||||||||
# Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js) | ||||||||||||
def javascript_importmap_tags(entry_point = "application", importmap: Rails.application.importmap) | ||||||||||||
def javascript_importmap_tags(entry_point = "application") | ||||||||||||
entry_point = entry_point.to_s | ||||||||||||
|
||||||||||||
importmap_identifier = | ||||||||||||
entry_point != "application" && Rails.application.importmaps.key?(entry_point) ? | ||||||||||||
entry_point : | ||||||||||||
"application" | ||||||||||||
importmap = Rails.application.importmaps.fetch(entry_point) | ||||||||||||
|
||||||||||||
safe_join [ | ||||||||||||
javascript_inline_importmap_tag(importmap.to_json(resolver: self)), | ||||||||||||
javascript_importmap_module_preload_tags(importmap), | ||||||||||||
|
@@ -10,7 +18,7 @@ def javascript_importmap_tags(entry_point = "application", importmap: Rails.appl | |||||||||||
|
||||||||||||
# Generate an inline importmap tag using the passed `importmap_json` JSON string. | ||||||||||||
# By default, `Rails.application.importmap.to_json(resolver: self)` is used. | ||||||||||||
def javascript_inline_importmap_tag(importmap_json = Rails.application.importmap.to_json(resolver: self)) | ||||||||||||
def javascript_inline_importmap_tag(importmap_json) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why you removed this default value declaration? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I removed it since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Or maybe something like:
Suggested change
Assuming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with passing the importmap as a param, since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have any particular preference. Let's see what others think. |
||||||||||||
tag.script importmap_json.html_safe, | ||||||||||||
type: "importmap", "data-turbo-track": "reload", nonce: request&.content_security_policy_nonce | ||||||||||||
end | ||||||||||||
|
@@ -24,7 +32,7 @@ def javascript_import_module_tag(*module_names) | |||||||||||
# Link tags for preloading all modules marked as preload: true in the `importmap` | ||||||||||||
# (defaults to Rails.application.importmap), such that they'll be fetched | ||||||||||||
# in advance by browsers supporting this link type (https://caniuse.com/?search=modulepreload). | ||||||||||||
def javascript_importmap_module_preload_tags(importmap = Rails.application.importmap) | ||||||||||||
def javascript_importmap_module_preload_tags(importmap) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why you removed this default value declaration? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as with |
||||||||||||
javascript_module_preload_tag(*importmap.preloaded_module_paths(resolver: self)) | ||||||||||||
end | ||||||||||||
|
||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.