class Sprockets::Webpack::WebpackDirectiveProcessor

Public Instance Methods

_call(_) click to toggle source
Calls superclass method
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 22
def _call(_)
  result = super
  joined_data = [result[:data], "\n\n\n", @webpack_data].compact.join
  result.merge(data: joined_data)
end
process_require_webpack_tree_directive(path = '.') click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 7
def process_require_webpack_tree_directive(path = '.')
  absolute_path = expand_relative_dirname(:require_tree, path)
  entry = entry_from_absolute_path(absolute_path)

  add_path_to_dependencies_list(absolute_path)
  add_webpack_config_to_dependencies_list

  compiled = driver_for(entry).compile
  logger.info "WEBPACK: #{compiled.benchmark}"

  assert_no_errors(compiled.errors)

  @webpack_data = compiled.data
end

Private Instance Methods

add_path_to_dependencies_list(path) click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 50
def add_path_to_dependencies_list(path)
  require_webpack_paths(*@environment.stat_sorted_tree_with_dependencies(path))
end
add_webpack_config_to_dependencies_list() click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 54
def add_webpack_config_to_dependencies_list
  @dependencies << "file-digest://#{webpack_config}"
end
assert_no_errors(errors) click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 30
def assert_no_errors(errors)
  fail WebpackError, errors.join("\n") if errors.any?
end
driver_for(entry) click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 44
def driver_for(entry)
  entry = String(entry)
  $webpack_drivers ||= {}
  $webpack_drivers[entry] ||= WebpackDriver.new(webpack_config, entry)
end
entry_from_absolute_path(absolute_path) click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 34
def entry_from_absolute_path(absolute_path)
  Pathname.new(absolute_path).join('index.js').tap do |entry|
    fail WebpackError, "#{entry} doesn't exist" unless entry.exist?
  end
end
logger() click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 64
def logger
  defined?(::Rails) ? ::Rails.logger : stderr_logger
end
require_webpack_paths(paths, deps) click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 58
def require_webpack_paths(paths, deps)
  paths.each.map(&:first).each do |path|
    @dependencies << "file-digest://#{path}"
  end
end
stderr_logger() click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 68
def stderr_logger
  @stderr_logger ||= Logger.new(STDERR)
end
webpack_config() click to toggle source
# File lib/sprockets/webpack/webpack_directive_processor.rb, line 40
def webpack_config
  defined?(::Rails) ? ::Rails.root.join('config/webpack.config.js') : 'webpack.config.js'
end