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
-
.reload ⇒ Object
Returns the value of attribute reload.
-
.splitter ⇒ Object
Returns the value of attribute splitter.
-
.stats_path ⇒ Object
Returns the value of attribute stats_path.
Class Method Summary collapse
- .assets ⇒ Object
- .configure {|_self| ... } ⇒ Object
- .load_assets ⇒ Object
- .load_stats ⇒ Object
- .split_asset_name(stats, asset_name) ⇒ Object
- .stats ⇒ Object
Class Attribute Details
.reload ⇒ Object
Returns the value of attribute reload.
13 14 15 |
# File 'lib/webpack_stats.rb', line 13 def reload @reload end |
.splitter ⇒ Object
Returns the value of attribute splitter.
13 14 15 |
# File 'lib/webpack_stats.rb', line 13 def splitter @splitter end |
.stats_path ⇒ Object
Returns the value of attribute stats_path.
13 14 15 |
# File 'lib/webpack_stats.rb', line 13 def stats_path @stats_path end |
Class Method Details
.assets ⇒ Object
19 20 21 |
# File 'lib/webpack_stats.rb', line 19 def assets @reload ? load_assets : @assets ||= load_assets end |
.configure {|_self| ... } ⇒ Object
15 16 17 |
# File 'lib/webpack_stats.rb', line 15 def configure yield self end |
.load_assets ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/webpack_stats.rb', line 31 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_stats ⇒ Object
27 28 29 |
# File 'lib/webpack_stats.rb', line 27 def load_stats JSON.parse File.read @stats_path end |
.split_asset_name(stats, asset_name) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/webpack_stats.rb', line 41 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 |
.stats ⇒ Object
23 24 25 |
# File 'lib/webpack_stats.rb', line 23 def stats @reload ? load_stats : @stats ||= load_stats end |