Module: WebpackStats

Defined in:
lib/webpack_stats.rb

Defined Under Namespace

Modules: Helper

Constant Summary collapse

REGEXP =
/(.+?)(?:-([0-9a-f]{20,}))?\.(\w+)/

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.reloadObject

Returns the value of attribute reload.



11
12
13
# File 'lib/webpack_stats.rb', line 11

def reload
  @reload
end

.splitterObject

Returns the value of attribute splitter.



11
12
13
# File 'lib/webpack_stats.rb', line 11

def splitter
  @splitter
end

.stats_pathObject

Returns the value of attribute stats_path.



11
12
13
# File 'lib/webpack_stats.rb', line 11

def stats_path
  @stats_path
end

Class Method Details

.assetsObject



17
18
19
# File 'lib/webpack_stats.rb', line 17

def assets
  @reload ? load_assets : @assets ||= load_assets
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (WebpackStats)

    the object that the method was called on



13
14
15
# File 'lib/webpack_stats.rb', line 13

def configure
  yield self
end

.load_assetsObject



29
30
31
32
33
34
35
36
37
# File 'lib/webpack_stats.rb', line 29

def load_assets
  ret = {}
  _stats = stats
  _stats['assets'].each do |asset|
    key, value = split_asset_name(_stats, asset['name'])
    ret[key] = value
  end
  ret
end

.load_statsObject



25
26
27
# File 'lib/webpack_stats.rb', line 25

def load_stats
  JSON.parse File.read @stats_path
end

.split_asset_name(stats, asset_name) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/webpack_stats.rb', line 39

def split_asset_name stats, asset_name
  if @splitter.respond_to? :call
    @splitter.call stats['publicPath'], asset_name
  else
    full_name, name, hash, ext = REGEXP.match(asset_name).to_a
    ["#{name}.#{ext}", File.join(stats['publicPath'], full_name)]
  end
end

.statsObject



21
22
23
# File 'lib/webpack_stats.rb', line 21

def stats
  @reload ? load_stats : @stats ||= load_stats
end