class VueRails::WebpackerAssetFinder

Constants

CLIENT_REQUIRE

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

Public Class Methods

compatible?() click to toggle source
# File lib/vue_rails/asset_finder.rb, line 14
def self.compatible?
  !!defined?(Webpacker)
end

Public Instance Methods

config() click to toggle source
# File lib/vue_rails/asset_finder.rb, line 71
def config
  Webpacker::Configuration
end
file_path(path) click to toggle source
# File lib/vue_rails/asset_finder.rb, line 81
def file_path path
  manifest.lookup_path(path)
end
find_asset(logical_path) click to toggle source
# File lib/vue_rails/asset_finder.rb, line 24
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 = 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
find_path(logical_path) click to toggle source
# File lib/vue_rails/asset_finder.rb, line 19
def find_path(logical_path)
  asset_path = manifest.lookup(logical_path).to_s
  asset_path.start_with?('http') ? asset_path : file_path(logical_path).to_s
end
manifest() click to toggle source
# File lib/vue_rails/asset_finder.rb, line 61
def manifest
  Webpacker::Manifest
end
output_path() click to toggle source
# File lib/vue_rails/asset_finder.rb, line 95
def output_path
  # Webpack1 /:output/:entry, Webpack3 /public/:output
  config.respond_to?(:output_path) ? config.output_path : 'public'
end