Sha256: cdf94455ca33b761ef4133fca60ab1874b5c6df81921243165090fc9e699b1dd

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

module ReactOnRails
  module WebpackerUtils
    def self.using_webpacker?
      ReactOnRails::Utils.gem_available?("webpacker")
    end

    def self.bundle_js_file_path_from_webpacker(bundle_name)
      # Note Webpacker 3.4.3 manifest lookup is inside of the public_output_path
      # [2] (pry) ReactOnRails::WebpackerUtils: 0> Webpacker.manifest.lookup("app-bundle.js")
      # "/webpack/development/app-bundle-c1d2b6ab73dffa7d9c0e.js"
      # Next line will throw if the file or manifest does not exist
      hashed_bundle_name = Webpacker.manifest.lookup!(bundle_name)

      if Webpacker.dev_server.running?
        "#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{hashed_bundle_name}"
      else
        File.expand_path(File.join("public", hashed_bundle_name)).to_s
      end
    end

    def self.webpacker_source_path
      Webpacker.config.source_path
    end

    def self.webpacker_public_output_path
      # Webpacker has the full absolute path of webpacker output files in a Pathname
      Webpacker.config.public_output_path.to_s
    end

    def self.manifest_exists?
      Webpacker.config.public_manifest_path.exist?
    end

    def self.webpacker_source_path_explicit?
      # WARNING: Calling private method `data` on Webpacker::Configuration, lib/webpacker/configuration.rb
      config_webpacker_yml = Webpacker.config.send(:data)
      config_webpacker_yml[:source_path].present?
    end

    def self.check_manifest_not_cached
      return unless using_webpacker? && Webpacker.config.cache_manifest?
      msg = <<-MSG.strip_heredoc
          ERROR: you have enabled cache_manifest in the #{Rails.env} env when using the
          ReactOnRails::TestHelper.configure_rspec_to_compile_assets helper
          To fix this: edit your config/webpacker.yml file and set cache_manifest to false for test.
      MSG
      puts wrap_message(msg)
      exit!
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
react_on_rails-11.1.7 lib/react_on_rails/webpacker_utils.rb
react_on_rails-11.1.6 lib/react_on_rails/webpacker_utils.rb
react_on_rails-11.1.5 lib/react_on_rails/webpacker_utils.rb
react_on_rails-11.1.4 lib/react_on_rails/webpacker_utils.rb
react_on_rails-11.1.3 lib/react_on_rails/webpacker_utils.rb
react_on_rails-11.1.2 lib/react_on_rails/webpacker_utils.rb