Skip to content

Commit 035ca6d

Browse files
committed
Drop the bundled shim
It's no longer needed with full support for import maps in all modern browsers.
1 parent e0c1676 commit 035ca6d

File tree

9 files changed

+3
-970
lines changed

9 files changed

+3
-970
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
With this approach you'll ship many small JavaScript files instead of one big JavaScript file. Thanks to HTTP/2 that no longer carries a material performance penalty during the initial transport, and in fact offers substantial benefits over the long run due to better caching dynamics. Whereas before any change to any JavaScript file included in your big bundle would invalidate the cache for the whole bundle, now only the cache for that single file is invalidated.
66

7-
There's [native support for import maps in Chrome/Edge 89+/Firefox 108+](https://caniuse.com/?search=importmap), and [a shim available](https://github.com/guybedford/es-module-shims) for any browser with basic ESM support. So your app will be able to work with all the evergreen browsers.
7+
[Import maps are supported natively in all major, modern browsers](https://caniuse.com/?search=importmap). If you need to work with legacy browsers without native support, you can explore using [the shim available](https://github.com/guybedford/es-module-shims).
88

99

1010
## Installation

app/assets/javascripts/es-module-shims.js

Lines changed: 0 additions & 926 deletions
This file was deleted.

app/assets/javascripts/es-module-shims.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/assets/javascripts/es-module-shims.min.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

app/helpers/importmap/importmap_tags_helper.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
module Importmap::ImportmapTagsHelper
22
# Setup all script tags needed to use an importmap-powered entrypoint (which defaults to application.js)
3-
def javascript_importmap_tags(entry_point = "application", shim: true, importmap: Rails.application.importmap)
3+
def javascript_importmap_tags(entry_point = "application", importmap: Rails.application.importmap)
44
safe_join [
55
javascript_inline_importmap_tag(importmap.to_json(resolver: self)),
66
javascript_importmap_module_preload_tags(importmap),
7-
(javascript_importmap_shim_nonce_configuration_tag if shim),
8-
(javascript_importmap_shim_tag if shim),
97
javascript_import_module_tag(entry_point)
10-
].compact, "\n"
8+
], "\n"
119
end
1210

1311
# Generate an inline importmap tag using the passed `importmap_json` JSON string.
@@ -17,20 +15,6 @@ def javascript_inline_importmap_tag(importmap_json = Rails.application.importmap
1715
type: "importmap", "data-turbo-track": "reload", nonce: request&.content_security_policy_nonce
1816
end
1917

20-
# Configure es-modules-shim with nonce support if the application is using a content security policy.
21-
def javascript_importmap_shim_nonce_configuration_tag
22-
if request&.content_security_policy
23-
tag.script({ nonce: request.content_security_policy_nonce }.to_json.html_safe,
24-
type: "esms-options", nonce: request.content_security_policy_nonce)
25-
end
26-
end
27-
28-
# Include the es-modules-shim needed to make importmaps work in browsers without native support (like Firefox + Safari).
29-
def javascript_importmap_shim_tag(minimized: true)
30-
javascript_include_tag minimized ? "es-module-shims.min.js" : "es-module-shims.js",
31-
async: true, "data-turbo-track": "reload", nonce: request&.content_security_policy_nonce
32-
end
33-
3418
# Import a named JavaScript module(s) using a script-module tag.
3519
def javascript_import_module_tag(*module_names)
3620
imports = Array(module_names).collect { |m| %(import "#{m}") }.join("\n")

bin/update-shim

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/importmap/engine.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Engine < ::Rails::Engine
4343

4444
initializer "importmap.assets" do |app|
4545
if app.config.respond_to?(:assets)
46-
app.config.assets.precompile += %w( es-module-shims.js es-module-shims.min.js es-module-shims.js.map )
4746
app.config.assets.paths << Rails.root.join("app/javascript")
4847
app.config.assets.paths << Rails.root.join("vendor/javascript")
4948
end

lib/shim.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/importmap_tags_helper_test.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ def content_security_policy_nonce
1919
end
2020
end
2121

22-
test "javascript_importmap_tags with and without shim" do
23-
assert_match /shim/, javascript_importmap_tags("application")
24-
assert_no_match /shim/, javascript_importmap_tags("application", shim: false)
25-
end
26-
2722
test "javascript_inline_importmap_tag" do
2823
assert_match \
2924
%r{<script type="importmap" data-turbo-track="reload">{\n \"imports\": {\n \"md5\": \"https://cdn.skypack.dev/md5\",\n \"not_there\": \"/nowhere.js\"\n }\n}</script>},
@@ -48,8 +43,6 @@ def content_security_policy_nonce
4843
@request = FakeRequest.new("iyhD0Yc0W+c=")
4944

5045
assert_match /nonce="iyhD0Yc0W\+c="/, javascript_inline_importmap_tag
51-
assert_match /nonce="iyhD0Yc0W\+c="/, javascript_importmap_shim_nonce_configuration_tag
52-
assert_match /nonce="iyhD0Yc0W\+c="/, javascript_importmap_shim_tag
5346
assert_match /nonce="iyhD0Yc0W\+c="/, javascript_import_module_tag("application")
5447
assert_match /nonce="iyhD0Yc0W\+c="/, javascript_importmap_module_preload_tags
5548
ensure

0 commit comments

Comments
 (0)