Class: Nanoc::Webpack::Filter

Inherits:
Filter
  • Object
show all
Includes:
FileUtils, Dependable, Spawn
Defined in:
lib/nanoc/webpack/filter/dependable.rb,
lib/nanoc/webpack/filter.rb

Defined Under Namespace

Modules: Dependable

Constant Summary

Constants included from Spawn

Spawn::Error

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Spawn

#spawn

Methods included from Dependable

#dependable, #expand, #root

Class Method Details

.default_argvArray<String>

The default argv for webpack

Examples:

Nanoc::Webpack.default_argv.concat ["--cache-type", "filesystem"]

Returns:

  • (Array<String>)

    Default argv for webpack



24
25
26
# File 'lib/nanoc/webpack/filter.rb', line 24

def self.default_argv
  @default_argv ||= []
end

Instance Method Details

#run(content, options = {}) ⇒ void

This method returns an undefined value.

Parameters:

  • content (String)

    The contents of a file

  • options (Hash) (defaults to: {})

    A hash of options



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nanoc/webpack/filter.rb', line 36

def run(content, options = {})
  options = Ryo.from(options)
  file = temporary_file(content)
  depend_on dependable(paths: options.depend_on, reject: options.reject)
              .map { items[_1] }
  argv = [*(options.argv || []), *default_argv]
  scan(argv)
  spawn "node",
        ["./node_modules/webpack/bin/webpack.js",
         *argv,
         "--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
         "--output-path", File.dirname(file.path),
         "--output-filename", File.basename(file.path)]
  File.read(file.path)
ensure
  file ? file.tap(&:unlink).close : nil
end