Class: Webpacker::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/webpacker/compiler.rb

Instance Method Summary collapse

Constructor Details

#initialize(webpacker) ⇒ Compiler

Returns a new instance of Compiler.



15
16
17
# File 'lib/webpacker/compiler.rb', line 15

def initialize(webpacker)
  @webpacker = webpacker
end

Instance Method Details

#compileObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/webpacker/compiler.rb', line 19

def compile
  if stale?
    run_webpack.tap do |success|
      # We used to only record the digest on success
      # However, the output file is still written on error, (at least with ts-loader), meaning that the
      # digest should still be updated. If it's not, you can end up in a situation where a recompile doesn't
      # take place when it should.
      # See https://github.com/rails/webpacker/issues/2113
      record_compilation_digest
    end
  else
    logger.info "Everything's up-to-date. Nothing to do"
    true
  end
end

#fresh?Boolean

Returns true if all the compiled packs are up to date with the underlying asset files.

Returns:

  • (Boolean)


36
37
38
# File 'lib/webpacker/compiler.rb', line 36

def fresh?
  watched_files_digest == last_compilation_digest
end

#stale?Boolean

Returns true if the compiled packs are out of date with the underlying asset files.

Returns:

  • (Boolean)


41
42
43
# File 'lib/webpacker/compiler.rb', line 41

def stale?
  !fresh?
end