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
20
# File 'lib/webpack_stats.rb', line 17

def assets
  load! if @reload || !@assets
  @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!Object



27
28
29
30
31
32
33
34
# File 'lib/webpack_stats.rb', line 27

def load!
  @stats = JSON.parse File.read @stats_path
  @assets = {}
  @stats['assets'].each do |asset|
    key, value = split_asset_name(@stats, asset['name'])
    @assets[key] = value
  end
end

.split_asset_name(stats, asset_name) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/webpack_stats.rb', line 36

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



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

def stats
  load! if @reload || !@stats
  @stats
end