Module: WebpackHelper
Instance Method Summary
collapse
Methods included from ViteHelper
#universal_path_to_stylesheet, #universal_stylesheet_link_tag, #vite_enabled?, #vite_page_entrypoint_paths
Instance Method Details
#prefetch_link_tag(source) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
|
# File 'app/helpers/webpack_helper.rb', line 6
def prefetch_link_tag(source)
href = asset_path(source)
link_tag = tag.link(rel: 'prefetch', href: href)
early_hints_link = "<#{href}>; rel=prefetch"
request.send_early_hints("Link" => early_hints_link)
link_tag
end
|
#webpack_bundle_tag(bundle) ⇒ Object
18
19
20
21
22
23
24
|
# File 'app/helpers/webpack_helper.rb', line 18
def webpack_bundle_tag(bundle)
if vite_enabled?
vite_javascript_tag bundle
else
javascript_include_tag(*webpack_entrypoint_paths(bundle))
end
end
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/helpers/webpack_helper.rb', line 42
def webpack_controller_bundle_tags(custom_action_name = nil)
chunks = []
action_name = custom_action_name || controller.action_name
action = case action_name
when 'create' then 'new'
when 'update' then 'edit'
else action_name
end
route = [*controller.controller_path.split('/'), action].compact
until chunks.any? || route.empty?
entrypoint = "pages.#{route.join('.')}"
begin
chunks = webpack_entrypoint_paths(entrypoint, extension: 'js')
rescue Gitlab::Webpack::Manifest::AssetMissingError
end
route.pop
end
chunks = webpack_entrypoint_paths("default", extension: 'js') if chunks.empty?
javascript_include_tag(*chunks)
end
|
#webpack_entrypoint_paths(source, extension: nil, exclude_duplicates: true) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/helpers/webpack_helper.rb', line 69
def webpack_entrypoint_paths(source, extension: nil, exclude_duplicates: true)
return "" unless source.present?
paths = Gitlab::Webpack::Manifest.entrypoint_paths(source)
paths.select! { |p| p.ends_with? ".#{extension}" } if extension
force_host = webpack_public_host
paths.map! { |p| "#{force_host}#{p}" } if force_host
if exclude_duplicates
@used_paths ||= []
new_paths = paths - @used_paths
@used_paths += new_paths
new_paths
else
paths
end
end
|
#webpack_preload_asset_tag(asset, options = {}) ⇒ Object
#webpack_public_host ⇒ Object
88
89
90
91
|
# File 'app/helpers/webpack_helper.rb', line 88
def webpack_public_host
ActionController::Base.asset_host.try(:chomp, '/')
end
|
#webpack_public_path ⇒ Object
93
94
95
96
97
|
# File 'app/helpers/webpack_helper.rb', line 93
def webpack_public_path
relative_path = Gitlab.config.gitlab.relative_url_root
webpack_path = Gitlab.config.webpack.public_path
File.join(webpack_public_host.to_s, relative_path.to_s, webpack_path.to_s, '')
end
|