Class: Sprockets::Browserify

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/sprockets/browserify.rb,
lib/sprockets/browserify/engine.rb

Overview

Postprocessor that runs the computed source of Javascript files through browserify, resulting in a self-contained files including all referenced modules

Defined Under Namespace

Classes: Engine

Instance Method Summary collapse

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sprockets/browserify.rb', line 15

def evaluate(scope, locals, &block)
  if (scope.pathname.dirname+'package.json').exist?
    deps = `#{browserify_executable} --list #{scope.pathname}`
    raise "Error finding dependencies" unless $?.success?

    deps.lines.drop(1).each{|path| scope.depend_on path.strip}

    @output ||= `#{browserify_executable} -d #{scope.pathname}`
    raise "Error compiling dependencies" unless $?.success?
    @output
  else
    data
  end
end

#prepareObject



12
13
# File 'lib/sprockets/browserify.rb', line 12

def prepare
end