summaryrefslogtreecommitdiff
path: root/app/helpers/webpack_helper.rb
blob: 6bacda9fe75153913e25ea770a344247629eb3b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'webpack/rails/manifest'

module WebpackHelper
  def webpack_bundle_tag(bundle)
    javascript_include_tag(*gitlab_webpack_asset_paths(bundle))
  end

  # override webpack-rails gem helper until changes can make it upstream
  def gitlab_webpack_asset_paths(source, extension: nil)
    return "" unless source.present?

    paths = Webpack::Rails::Manifest.asset_paths(source)
    if extension
      paths = paths.select { |p| p.ends_with? ".#{extension}" }
    end

    # include full webpack-dev-server url for rspec tests running locally
    if Rails.env.test? && Rails.configuration.webpack.dev_server.enabled
      host = Rails.configuration.webpack.dev_server.host
      port = Rails.configuration.webpack.dev_server.port
      protocol = Rails.configuration.webpack.dev_server.https ? 'https' : 'http'

      paths.map! do |p|
        "#{protocol}://#{host}:#{port}#{p}"
      end
    end

    paths
  end
end