class React::ServerRendering::WebpackerManifestContainer

Get a compiled file from Webpacker. It may come from:

Constants

CLIENT_REQUIRE

This pattern matches the code that initializes the dev-server client.

Public Class Methods

compatible?() click to toggle source
# File lib/react/server_rendering/webpacker_manifest_container.rb, line 20
def self.compatible?
  !!defined?(Webpacker)
end

Public Instance Methods

config() click to toggle source
# File lib/react/server_rendering/webpacker_manifest_container.rb, line 67
def config
  Webpacker::Configuration
end
file_path(path) click to toggle source
# File lib/react/server_rendering/webpacker_manifest_container.rb, line 77
def file_path path
  manifest.lookup_path(path)
end
find_asset(logical_path) click to toggle source
# File lib/react/server_rendering/webpacker_manifest_container.rb, line 25
def find_asset(logical_path)
  # raises if not found
  asset_path = manifest.lookup(logical_path).to_s
  if asset_path.start_with?('http')
    # Get a file from the webpack-dev-server
    dev_server_asset = URI.open(asset_path).read
    # Remove `webpack-dev-server/client/index.js` code which causes ExecJS to 💥
    dev_server_asset.sub!(CLIENT_REQUIRE, '//\0')
    dev_server_asset
  else
    # Read the already-compiled pack:
    full_path = file_path(logical_path).to_s
    File.read(full_path)
  end
end
manifest() click to toggle source
# File lib/react/server_rendering/webpacker_manifest_container.rb, line 57
def manifest
  Webpacker::Manifest
end
output_path() click to toggle source
# File lib/react/server_rendering/webpacker_manifest_container.rb, line 90
def output_path
  # Webpack1 /:output/:entry, Webpack3 /public/:output
  config.respond_to?(:output_path) ? config.output_path : 'public'
end