@@ -26,15 +26,27 @@ def vite_asset_path(name, **options)
26
26
def vite_javascript_tag ( *names ,
27
27
type : 'module' ,
28
28
asset_type : :javascript ,
29
+ integrity : false ,
29
30
skip_preload_tags : false ,
30
31
skip_style_tags : false ,
31
32
crossorigin : 'anonymous' ,
32
33
media : 'screen' ,
33
34
**options )
34
35
entries = vite_manifest . resolve_entries ( *names , type : asset_type )
35
- tags = javascript_include_tag ( *entries . fetch ( :scripts ) , crossorigin : crossorigin , type : type , extname : false , **options )
36
- tags << vite_preload_tag ( *entries . fetch ( :imports ) , crossorigin : crossorigin , **options ) unless skip_preload_tags
36
+ tags = '' . html_safe
37
+
38
+ entries . fetch ( :main ) . each do |src , attrs |
39
+ tags << javascript_include_tag ( src , crossorigin : crossorigin , type : type , extname : false , **attrs , **options )
40
+ end
41
+
42
+ unless skip_preload_tags
43
+ entries . fetch ( :imports ) . each do |href , attrs |
44
+ tags << vite_preload_tag ( href , crossorigin : crossorigin , **attrs , **options )
45
+ end
46
+ end
47
+
37
48
tags << stylesheet_link_tag ( *entries . fetch ( :stylesheets ) , media : media , crossorigin : crossorigin , **options ) unless skip_style_tags
49
+
38
50
tags
39
51
end
40
52
@@ -44,9 +56,12 @@ def vite_typescript_tag(*names, **options)
44
56
end
45
57
46
58
# Public: Renders a <link> tag for the specified Vite entrypoints.
47
- def vite_stylesheet_tag ( *names , **options )
48
- style_paths = names . map { |name | vite_asset_path ( name , type : :stylesheet ) }
49
- stylesheet_link_tag ( *style_paths , **options )
59
+ def vite_stylesheet_tag ( *names , integrity : false , **options )
60
+ '' . html_safe . tap do |tags |
61
+ vite_manifest . resolve_entries ( *names , type : :stylesheet ) . fetch ( :main ) . each do |href , attrs |
62
+ tags << stylesheet_link_tag ( href , **attrs , **options )
63
+ end
64
+ end
50
65
end
51
66
52
67
# Public: Renders an <img> tag for the specified Vite asset.
@@ -68,11 +83,13 @@ def vite_manifest
68
83
end
69
84
70
85
# Internal: Renders a modulepreload link tag.
71
- def vite_preload_tag ( *sources , crossorigin :, **options )
72
- sources . map { |source |
73
- href = path_to_asset ( source )
74
- try ( :request ) . try ( :send_early_hints , 'Link' => %(<#{ href } >; rel=modulepreload; as=script; crossorigin=#{ crossorigin } ) )
75
- tag . link ( rel : 'modulepreload' , href : href , as : 'script' , crossorigin : crossorigin , **options )
76
- } . join ( "\n " ) . html_safe
86
+ def vite_preload_tag ( source , crossorigin :, **options )
87
+ href = path_to_asset ( source )
88
+ try ( :request ) . try ( :send_early_hints , 'Link' => %(<#{ href } >; rel=modulepreload; as=script; crossorigin=#{ crossorigin } ) . tap { |hint |
89
+ if integrity = options [ :integrity ]
90
+ hint << "; integrity: #{ integrity } "
91
+ end
92
+ } )
93
+ tag . link ( rel : 'modulepreload' , href : href , as : 'script' , type : 'module' , crossorigin : crossorigin , **options )
77
94
end
78
95
end
0 commit comments