module Webpacker::Compiler
Public Instance Methods
compile()
click to toggle source
# File lib/webpacker/compiler.rb, line 14 def compile return unless compile? cache_source_timestamp compile_task.invoke compile_task.reenable end
compile?()
click to toggle source
# File lib/webpacker/compiler.rb, line 21 def compile? return true unless File.exist?(cached_timestamp_path) return true unless File.exist?(Webpacker::Configuration.output_path) File.read(cached_timestamp_path) != current_source_timestamp end
default_watched_paths()
click to toggle source
# File lib/webpacker/compiler.rb, line 28 def default_watched_paths ["#{Webpacker::Configuration.source}/**/*", "yarn.lock", "package.json", "config/webpack/**/*"].freeze end
Private Instance Methods
cache_source_timestamp()
click to toggle source
# File lib/webpacker/compiler.rb, line 38 def cache_source_timestamp File.write(cached_timestamp_path, current_source_timestamp) end
cached_timestamp_path()
click to toggle source
# File lib/webpacker/compiler.rb, line 42 def cached_timestamp_path FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir) Rails.root.join(cache_dir, ".compiler-timestamp") end
compile_task()
click to toggle source
# File lib/webpacker/compiler.rb, line 47 def compile_task @compile_task ||= load_rake_task("webpacker:compile") end
current_source_timestamp()
click to toggle source
# File lib/webpacker/compiler.rb, line 33 def current_source_timestamp files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) } files.map { |f| File.mtime(f).utc.to_i }.max.to_s end
load_rake_task(name)
click to toggle source
# File lib/webpacker/compiler.rb, line 51 def load_rake_task(name) load_rakefile unless Rake::Task.task_defined?(name) Rake::Task[name] end
load_rakefile()
click to toggle source
# File lib/webpacker/compiler.rb, line 56 def load_rakefile @load_rakefile ||= Rake.load_rakefile(Rails.root.join("Rakefile")) end