Module: ViteHelper
- Included in:
- ApplicationHelper, WebpackHelper
- Defined in:
- app/helpers/vite_helper.rb
Instance Method Summary collapse
- #universal_path_to_stylesheet(path, **options) ⇒ Object
- #universal_stylesheet_link_tag(path, **options) ⇒ Object
- #vite_enabled? ⇒ Boolean
- #vite_page_entrypoint_paths(custom_action_name = nil) ⇒ Object
Instance Method Details
#universal_path_to_stylesheet(path, **options) ⇒ Object
44 45 46 47 48 |
# File 'app/helpers/vite_helper.rb', line 44 def universal_path_to_stylesheet(path, **) return ActionController::Base.helpers.stylesheet_path(path, **) unless vite_enabled? ViteRuby.instance.manifest.path_for(css_entrypoint_name(path), **) end |
#universal_stylesheet_link_tag(path, **options) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/helpers/vite_helper.rb', line 36 def universal_stylesheet_link_tag(path, **) return stylesheet_link_tag(path, **) unless vite_enabled? [:extname] = false vite_stylesheet_tag(css_entrypoint_name(path), **) end |
#vite_enabled? ⇒ Boolean
4 5 6 7 8 9 |
# File 'app/helpers/vite_helper.rb', line 4 def vite_enabled? # vite is not production ready yet return false if Rails.env.production? Gitlab::Utils.to_boolean(ViteRuby.env['VITE_ENABLED'], default: false) end |
#vite_page_entrypoint_paths(custom_action_name = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/vite_helper.rb', line 11 def vite_page_entrypoint_paths(custom_action_name = nil) action_name = custom_action_name || controller.action_name action = case action_name when 'create' then 'new' when 'update' then 'edit' else action_name end parts = (controller.controller_path.split('/') << action) parts.map .with_index { |part, idx| "pages.#{(parts[0, idx] << part).join('.')}.js" } .filter do |name| # always truthy in dev mode for non-existing entrypoints # we return /* doesn't exist */ on the dev server for such false positives ViteRuby.instance.manifest.path_for(name) rescue ViteRuby::MissingEntrypointError # we don't know if an entrypoint exists for each of the controller action part # for example: it might be present for the last part but not for the first part # - pages.merge_requests.js -> empty, error thrown # - pages.merge_requests.edit.js -> found false end end |