shakapacker 8.1.0 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +21 -1
- data/gemfiles/Gemfile-rails.6.0.x +1 -0
- data/gemfiles/Gemfile-rails.6.1.x +1 -0
- data/gemfiles/Gemfile-rails.7.0.x +1 -0
- data/lib/shakapacker/helper.rb +26 -14
- data/lib/shakapacker/version.rb +1 -1
- data/package.json +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e79664eb847e6cd529faef7596863300465e9ae31cccde5042e86363d3bf8a66
|
4
|
+
data.tar.gz: 57c9eb85b20b964f80bf458a1a6f8f0db79c5bf394819f7e687b973e10839a77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed317c5485ff9db1aabc55ce8ac2e9a53975882f180faa65e1cb4565175956c416e9543d8e5683906d77d3b992f282159a049ef689d6b03de6a90c76d9269a6b
|
7
|
+
data.tar.gz: 557c44369b8af2c300f8bb71810fead6ab59b37770cd7b6898a11b901c73c4da241df82591190ccc65ec3d5b5b3e7b4ce4e055cee51e03bd297d585efd49ba3e
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,11 @@ _next_ branch is for v8 changes
|
|
10
10
|
## [Unreleased]
|
11
11
|
Changes since the last non-beta release.
|
12
12
|
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Support for `async` attribute in `javascript_pack_tag`, `append_javascript_pack_tag`, and `prepend_javascript_pack_tag`. [PR 554](https://github.com/shakacode/shakapacker/pull/554) by [AbanoubGhadban](https://github.com/abanoubghadban).
|
16
|
+
- Allow `babel-loader` v10. [PR 552](https://github.com/shakacode/shakapacker/pull/552) by [shoeyn](https://github.com/shoeyn).
|
17
|
+
|
13
18
|
## [v8.1.0] - January 20, 2025
|
14
19
|
|
15
20
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -275,7 +275,7 @@ You can provide multiple packs and other attributes. Note, `defer` defaults to s
|
|
275
275
|
```
|
276
276
|
|
277
277
|
The resulting HTML would look like this:
|
278
|
-
```
|
278
|
+
```html
|
279
279
|
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
|
280
280
|
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
|
281
281
|
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbo-track="reload" defer"></script>
|
@@ -287,6 +287,26 @@ In this output, both the calendar and map codes might refer to other common libr
|
|
287
287
|
|
288
288
|
Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
289
289
|
|
290
|
+
The `javascript_pack_tag` also supports the `async` attribute, which you can enable by passing `async: true`:
|
291
|
+
|
292
|
+
```erb
|
293
|
+
<%= javascript_pack_tag 'application', async: true %>
|
294
|
+
```
|
295
|
+
|
296
|
+
This will generate script tags with the `async` attribute, which allows the browser to download and execute the script asynchronously without blocking HTML parsing:
|
297
|
+
|
298
|
+
```html
|
299
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" async></script>
|
300
|
+
<script src="/packs/application~runtime-16838bab065ae1e314.js" async></script>
|
301
|
+
<script src="/packs/application-1016838bab065ae1e314.js" async></script>
|
302
|
+
```
|
303
|
+
|
304
|
+
Note that when using `async: true`, scripts may execute in any order as soon as they're downloaded, which could cause issues if your code has dependencies between files. In most cases, `defer` (the default) is preferred as it maintains execution order.
|
305
|
+
|
306
|
+
> [!NOTE]
|
307
|
+
>
|
308
|
+
> When both `async` and `defer` attributes are specified, `async` takes precedence according to HTML5 specifications. So if you pass both `async: true` and `defer: true`, the script tag will use `async`.
|
309
|
+
|
290
310
|
**Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the `stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page.
|
291
311
|
|
292
312
|
```erb
|
data/lib/shakapacker/helper.rb
CHANGED
@@ -95,22 +95,25 @@ module Shakapacker::Helper
|
|
95
95
|
#
|
96
96
|
# <%= javascript_pack_tag 'calendar' %>
|
97
97
|
# <%= javascript_pack_tag 'map' %>
|
98
|
-
def javascript_pack_tag(*names, defer: true, **options)
|
98
|
+
def javascript_pack_tag(*names, defer: true, async: false, **options)
|
99
99
|
if @javascript_pack_tag_loaded
|
100
100
|
raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " \
|
101
101
|
"Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
|
102
102
|
end
|
103
103
|
|
104
|
-
append_javascript_pack_tag(*names, defer: defer)
|
105
|
-
|
106
|
-
|
104
|
+
append_javascript_pack_tag(*names, defer: defer, async: async)
|
105
|
+
sync = sources_from_manifest_entrypoints(javascript_pack_tag_queue[:sync], type: :javascript)
|
106
|
+
async = sources_from_manifest_entrypoints(javascript_pack_tag_queue[:async], type: :javascript) - sync
|
107
|
+
deferred = sources_from_manifest_entrypoints(javascript_pack_tag_queue[:deferred], type: :javascript) - sync - async
|
107
108
|
|
108
109
|
@javascript_pack_tag_loaded = true
|
109
110
|
|
110
111
|
capture do
|
111
|
-
concat javascript_include_tag(*
|
112
|
-
concat "\n" if
|
113
|
-
concat javascript_include_tag(*
|
112
|
+
concat javascript_include_tag(*async, **options.dup.tap { |o| o[:async] = true })
|
113
|
+
concat "\n" if async.any? && deferred.any?
|
114
|
+
concat javascript_include_tag(*deferred, **options.dup.tap { |o| o[:defer] = true })
|
115
|
+
concat "\n" if sync.any? && deferred.any?
|
116
|
+
concat javascript_include_tag(*sync, **options)
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
@@ -179,27 +182,35 @@ module Shakapacker::Helper
|
|
179
182
|
nil
|
180
183
|
end
|
181
184
|
|
182
|
-
def append_javascript_pack_tag(*names, defer: true)
|
183
|
-
update_javascript_pack_tag_queue(defer: defer) do |hash_key|
|
185
|
+
def append_javascript_pack_tag(*names, defer: true, async: false)
|
186
|
+
update_javascript_pack_tag_queue(defer: defer, async: async) do |hash_key|
|
184
187
|
javascript_pack_tag_queue[hash_key] |= names
|
185
188
|
end
|
186
189
|
end
|
187
190
|
|
188
|
-
def prepend_javascript_pack_tag(*names, defer: true)
|
189
|
-
update_javascript_pack_tag_queue(defer: defer) do |hash_key|
|
191
|
+
def prepend_javascript_pack_tag(*names, defer: true, async: false)
|
192
|
+
update_javascript_pack_tag_queue(defer: defer, async: async) do |hash_key|
|
190
193
|
javascript_pack_tag_queue[hash_key].unshift(*names)
|
191
194
|
end
|
192
195
|
end
|
193
196
|
|
194
197
|
private
|
195
198
|
|
196
|
-
def update_javascript_pack_tag_queue(defer:)
|
199
|
+
def update_javascript_pack_tag_queue(defer:, async:)
|
197
200
|
if @javascript_pack_tag_loaded
|
198
201
|
raise "You can only call #{caller_locations(1..1).first.base_label} before javascript_pack_tag helper. " \
|
199
202
|
"Please refer to https://github.com/shakacode/shakapacker/blob/main/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
|
200
203
|
end
|
201
204
|
|
202
|
-
|
205
|
+
# When both async and defer are specified, async takes precedence per HTML5 spec
|
206
|
+
hash_key = if async
|
207
|
+
:async
|
208
|
+
elsif defer
|
209
|
+
:deferred
|
210
|
+
else
|
211
|
+
:sync
|
212
|
+
end
|
213
|
+
yield(hash_key)
|
203
214
|
|
204
215
|
# prevent rendering Array#to_s representation when used with <%= … %> syntax
|
205
216
|
nil
|
@@ -207,8 +218,9 @@ module Shakapacker::Helper
|
|
207
218
|
|
208
219
|
def javascript_pack_tag_queue
|
209
220
|
@javascript_pack_tag_queue ||= {
|
221
|
+
async: [],
|
210
222
|
deferred: [],
|
211
|
-
|
223
|
+
sync: []
|
212
224
|
}
|
213
225
|
end
|
214
226
|
|
data/lib/shakapacker/version.rb
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "shakapacker",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.2.0",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"homepage": "https://github.com/shakacode/shakapacker",
|
6
6
|
"bugs": {
|
@@ -55,7 +55,7 @@
|
|
55
55
|
"@babel/runtime": "^7.17.9",
|
56
56
|
"@types/babel__core": "^7.0.0",
|
57
57
|
"@types/webpack": "^5.0.0",
|
58
|
-
"babel-loader": "^8.2.4 || ^9.0.0",
|
58
|
+
"babel-loader": "^8.2.4 || ^9.0.0 || ^10.0.0",
|
59
59
|
"compression-webpack-plugin": "^9.0.0 || ^10.0.0|| ^11.0.0",
|
60
60
|
"terser-webpack-plugin": "^5.3.1",
|
61
61
|
"webpack": "^5.72.0",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shakapacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2025-
|
13
|
+
date: 2025-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -284,7 +284,7 @@ homepage: https://github.com/shakacode/shakapacker
|
|
284
284
|
licenses:
|
285
285
|
- MIT
|
286
286
|
metadata:
|
287
|
-
source_code_uri: https://github.com/shakacode/shakapacker/tree/v8.
|
287
|
+
source_code_uri: https://github.com/shakacode/shakapacker/tree/v8.2.0
|
288
288
|
post_install_message:
|
289
289
|
rdoc_options: []
|
290
290
|
require_paths:
|