@@ -59,7 +59,29 @@ def image_pack_tag(name, **options)
59
59
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
60
60
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
61
61
def javascript_pack_tag ( *names , **options )
62
- javascript_include_tag ( *sources_from_pack_manifest ( names , type : :javascript ) , **options )
62
+ javascript_include_tag ( *sources_from_manifest_entries ( names , type : :javascript ) , **options )
63
+ end
64
+
65
+ # Creates script tags that references the chunks from entrypoints when using split chunks API,
66
+ # as compiled by webpack per the entries list in config/webpack/shared.js.
67
+ # By default, this list is auto-generated to match everything in
68
+ # app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
69
+ # See: https://webpack.js.org/plugins/split-chunks-plugin/
70
+ # Example:
71
+ #
72
+ # <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
73
+ # <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
74
+ # <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
75
+ # <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
76
+ # <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
77
+ # <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
78
+ # DO:
79
+ # <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
80
+ # DON'T:
81
+ # <%= javascript_packs_with_chunks_tag 'calendar' %>
82
+ # <%= javascript_packs_with_chunks_tag 'map' %>
83
+ def javascript_packs_with_chunks_tag ( *names , **options )
84
+ javascript_include_tag ( *sources_from_manifest_entrypoints ( names , type : :javascript ) , **options )
63
85
end
64
86
65
87
# Creates a link tag that references the named pack file, as compiled by webpack per the entries list
@@ -80,7 +102,7 @@ def javascript_pack_tag(*names, **options)
80
102
# <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
81
103
def stylesheet_pack_tag ( *names , **options )
82
104
if current_webpacker_instance . config . extract_css?
83
- stylesheet_link_tag ( *sources_from_pack_manifest ( names , type : :stylesheet ) , **options )
105
+ stylesheet_link_tag ( *sources_from_manifest_entries ( names , type : :stylesheet ) , **options )
84
106
end
85
107
end
86
108
@@ -89,7 +111,11 @@ def stylesheet?(name)
89
111
File . extname ( name ) == ".css"
90
112
end
91
113
92
- def sources_from_pack_manifest ( names , type :)
114
+ def sources_from_manifest_entries ( names , type :)
93
115
names . map { |name | current_webpacker_instance . manifest . lookup! ( name , type : type ) } . flatten
94
116
end
117
+
118
+ def sources_from_manifest_entrypoints ( names , type :)
119
+ names . map { |name | current_webpacker_instance . manifest . lookup_pack_with_chunks! ( name , type : type ) } . flatten . uniq
120
+ end
95
121
end
0 commit comments