importmap-rails 0.8.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -12
- data/app/assets/javascripts/es-module-shims.js +778 -776
- data/app/assets/javascripts/es-module-shims.js.map +1 -0
- data/app/assets/javascripts/es-module-shims.min.js +3 -1
- data/lib/importmap/engine.rb +18 -12
- data/lib/importmap/reloader.rb +1 -1
- data/lib/importmap/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f918e23d26d5143a331af11f787bf21e8f05faa0eb6b37bd224eecb83bc2eb1d
|
4
|
+
data.tar.gz: cb925e10a5219501ea16f065b21ae96838eeac65b8555aea796331f01a6c0b04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ae8ef2048023b5f761eb4d3b9b9b16ecf7cba30b25a6e7581acf70f3d113ab8658554a962ee162151caebacb37ccb8b2ee9f7604f679fe411f437ad1b38f42c
|
7
|
+
data.tar.gz: aff89a7331f5c6702c4f02701a3f8ccb89be944d35c4dc34385b9fbe81384dd73dcc62aa26f73e6d823c12af5ebc39a914b59e51d36667dff2b46ee3436af849
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ There's [native support for import maps in Chrome/Edge 89+](https://caniuse.com/
|
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
Importmap for Rails is automatically included in Rails 7+ for new applications, but you can also install it manually in existing applications:
|
12
|
+
Importmap for Rails is automatically included in Rails 7+ for new applications, but you can also install it manually in existing applications:
|
13
13
|
|
14
14
|
1. Add `importmap-rails` to your Gemfile with `gem 'importmap-rails'`
|
15
15
|
2. Run `./bin/bundle install`
|
@@ -43,7 +43,7 @@ For example:
|
|
43
43
|
|
44
44
|
```rb
|
45
45
|
# config/importmaps.rb
|
46
|
-
pin "react" to "https://ga.jspm.io/npm:react@17.0.2/index.js"
|
46
|
+
pin "react", to: "https://ga.jspm.io/npm:react@17.0.2/index.js"
|
47
47
|
```
|
48
48
|
|
49
49
|
means "everytime you see `import React from "react"`
|
@@ -188,7 +188,7 @@ pin "@github/hotkey", to: "https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/inde
|
|
188
188
|
pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js"
|
189
189
|
|
190
190
|
# app/views/layouts/application.html.erb
|
191
|
-
<%= javascript_importmap_tags %>
|
191
|
+
<%= javascript_importmap_tags %>
|
192
192
|
|
193
193
|
# will include the following link before the importmap is setup:
|
194
194
|
<link rel="modulepreload" href="https://ga.jspm.io/npm:@github/hotkey@1.4.4/dist/index.js">
|
@@ -199,7 +199,7 @@ pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js"
|
|
199
199
|
|
200
200
|
By default, Rails loads import map definition from the application's `config/importmap.rb` to the `Importmap::Map` object available at `Rails.application.importmap`.
|
201
201
|
|
202
|
-
You can combine multiple import maps by
|
202
|
+
You can combine multiple import maps by adding paths to additional import map configs to `Rails.application.config.importmap.paths`. For example, appending import maps defined in Rails engines:
|
203
203
|
|
204
204
|
```ruby
|
205
205
|
# my_engine/lib/my_engine/engine.rb
|
@@ -207,8 +207,9 @@ You can combine multiple import maps by drawing their definitions onto the `Rail
|
|
207
207
|
module MyEngine
|
208
208
|
class Engine < ::Rails::Engine
|
209
209
|
# ...
|
210
|
-
initializer "my-engine.importmap",
|
211
|
-
app.importmap.
|
210
|
+
initializer "my-engine.importmap", before: "importmap" do |app|
|
211
|
+
app.config.importmap.paths << Engine.root.join("config/importmap.rb")
|
212
|
+
# ...
|
212
213
|
end
|
213
214
|
end
|
214
215
|
end
|
@@ -238,14 +239,19 @@ end
|
|
238
239
|
|
239
240
|
Generating the import map json and modulepreloads may require resolving hundreds of assets. This can take a while, so these operations are cached, but in development and test, we watch for changes to both `config/importmap.rb` and files in `app/javascript` to clear this cache. This feature can be controlled in an environment configuration file via the boolean `config.importmap.sweep_cache`.
|
240
241
|
|
241
|
-
If you're pinning local files from outside of `app/javascript`, you'll need to add them to the cache sweeper configuration or restart your development server upon changes to those external files.
|
242
|
+
If you're pinning local files from outside of `app/javascript`, you'll need to add them to the cache sweeper configuration or restart your development server upon changes to those external files. For example, here's how you can do it for Rails engine:
|
242
243
|
|
243
244
|
```ruby
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
245
|
+
# my_engine/lib/my_engine/engine.rb
|
246
|
+
|
247
|
+
module MyEngine
|
248
|
+
class Engine < ::Rails::Engine
|
249
|
+
# ...
|
250
|
+
initializer "my-engine.importmap", before: "importmap" do |app|
|
251
|
+
# ...
|
252
|
+
app.config.importmap.cache_sweepers << Engine.root.join("app/assets/javascripts")
|
253
|
+
end
|
254
|
+
end
|
249
255
|
end
|
250
256
|
```
|
251
257
|
|