Class: Condenser::RollupProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/condenser/processors/rollup_processor.rb

Defined Under Namespace

Classes: Runner

Constant Summary collapse

@@setup =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = nil, prefix: nil, dynamic_imports: :inline) ⇒ RollupProcessor

Returns a new instance of RollupProcessor.

Parameters:

  • prefix (string) (defaults to: nil)

    string to prefix to the url of dynamic imports

  • imports (symbol)

    :inline will inline all the imports in the output file if possible. false will keep all the imports as imports. :local will not inline URLS.

  • dynamic_imports (symbol) (defaults to: :inline)

    Default is :local :inline - Inline dynamic imports into the output file if possible. :local - Same as :inline except for URLs are kept as URLs :keep - Keep the dynamic imports but rewrite the import as a URL



47
48
49
50
51
52
# File 'lib/condenser/processors/rollup_processor.rb', line 47

def initialize(dir = nil, prefix: nil, dynamic_imports: :inline)
  self.class.install_npm_packages(dir)
  @npm_dir = dir
  @prefix = prefix
  @dynamic_imports = dynamic_imports
end

Class Method Details

.call(environment, input) ⇒ Object



26
27
28
# File 'lib/condenser/processors/rollup_processor.rb', line 26

def self.call(environment, input)
  new(environment.npm_path).call(environment, input)
end

.install_npm_packages(npm_path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/condenser/processors/rollup_processor.rb', line 14

def self.install_npm_packages(npm_path)
  return if @@setup
  
  ::Condenser::NodeProcessor.new(npm_path).npm_install(
    'rollup',
    '@rollup/plugin-commonjs',
    '@rollup/plugin-node-resolve',
    '@rollup/plugin-replace'
  )
  @@setup = true
end

.setup(environment) ⇒ Object



10
11
12
# File 'lib/condenser/processors/rollup_processor.rb', line 10

def self.setup(environment)
  install_npm_packages(environment.npm_path)
end

Instance Method Details

#call(environment, input) ⇒ Object



54
55
56
# File 'lib/condenser/processors/rollup_processor.rb', line 54

def call(environment, input)
  Runner.new(@npm_dir, prefix: @prefix, dynamic_imports: @dynamic_imports).call(environment, input)
end

#nameObject



30
31
32
# File 'lib/condenser/processors/rollup_processor.rb', line 30

def name
  self.class.name
end

#optionsObject



34
35
36
# File 'lib/condenser/processors/rollup_processor.rb', line 34

def options
  {prefix: @prefix, dynamic_imports: @dynamic_imports}
end