update webpack helper to automatically include route-based entry points
This commit is contained in:
parent
900124810c
commit
dd75c337e5
2 changed files with 19 additions and 0 deletions
|
@ -5,6 +5,24 @@ module WebpackHelper
|
||||||
javascript_include_tag(*gitlab_webpack_asset_paths(bundle, force_same_domain: force_same_domain))
|
javascript_include_tag(*gitlab_webpack_asset_paths(bundle, force_same_domain: force_same_domain))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def webpack_controller_bundle_tags
|
||||||
|
bundles = []
|
||||||
|
segments = [*controller.controller_path.split('/'), controller.action_name].compact
|
||||||
|
|
||||||
|
until segments.empty?
|
||||||
|
begin
|
||||||
|
asset_paths = gitlab_webpack_asset_paths("pages.#{segments.join('.')}", extension: 'js')
|
||||||
|
bundles.unshift(*asset_paths)
|
||||||
|
rescue Webpack::Rails::Manifest::EntryPointMissingError
|
||||||
|
# no bundle exists for this path
|
||||||
|
end
|
||||||
|
|
||||||
|
segments.pop
|
||||||
|
end
|
||||||
|
|
||||||
|
javascript_include_tag(*bundles)
|
||||||
|
end
|
||||||
|
|
||||||
# override webpack-rails gem helper until changes can make it upstream
|
# override webpack-rails gem helper until changes can make it upstream
|
||||||
def gitlab_webpack_asset_paths(source, extension: nil, force_same_domain: false)
|
def gitlab_webpack_asset_paths(source, extension: nil, force_same_domain: false)
|
||||||
return "" unless source.present?
|
return "" unless source.present?
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
= webpack_bundle_tag "webpack_runtime"
|
= webpack_bundle_tag "webpack_runtime"
|
||||||
= webpack_bundle_tag "common"
|
= webpack_bundle_tag "common"
|
||||||
= webpack_bundle_tag "main"
|
= webpack_bundle_tag "main"
|
||||||
|
= webpack_controller_bundle_tags
|
||||||
= webpack_bundle_tag "raven" if current_application_settings.clientside_sentry_enabled
|
= webpack_bundle_tag "raven" if current_application_settings.clientside_sentry_enabled
|
||||||
= webpack_bundle_tag "test" if Rails.env.test?
|
= webpack_bundle_tag "test" if Rails.env.test?
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue