Commit 7d8e595c authored by Evaryont's avatar Evaryont

webpack helpers for linking to assets

parent acd10a2d
require 'json'
module WebpackStatsLoader
def webpack_stats
return @webpack_stats if @webpack_stats
File.open('.tmp/dist/stats.json') do |stats_file|
stats = JSON.load(stats_file)
@webpack_stats = stats
end
end
def link_webpack_css_chunk(chunkname)
output = StringIO.new
[*webpack_stats["assetsByChunkName"][chunkname]].each do |assets|
css_assets = [*assets].select { |filename| filename =~ /.css$/ }
css_assets.each do |filename|
output << "<link rel='stylesheet' href='/#{filename}' integrity='#{webpack_stats["integrity"][chunkname][filename]}' crossorigin='#{webpack_stats['crossOriginLoading']}' />"
end
end
output.string
end
def link_webpack_js_chunk(chunkname)
output = StringIO.new
[*webpack_stats["assetsByChunkName"][chunkname]].each do |assets|
js_assets = [*assets].select { |filename| filename =~ /.js$/ }
js_assets.each do |filename|
output << "<script src='/#{filename}' integrity='#{webpack_stats["integrity"][chunkname][filename]}' crossorigin='#{webpack_stats['crossOriginLoading']}'></script>"
end
end
output.string
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment