webpack_stats 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/webpack_stats.rb +66 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59a8a4a8645c8dd94e45909a89e3b68286126d14
|
4
|
+
data.tar.gz: 8ea48f885cbabae4aad8f5b17ef02ca1451fd2ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df051c286619ef36348704a5a671c0afc4625afc117937831bd180ef2115a9bfcb832b3b51df13b3768f8bebd2842c1fe04ac366d3b9baba2c6bf67dff333b1d
|
7
|
+
data.tar.gz: c53b2bed9a1230ff138f0c7f9dc1f1eda1d0d2b90fb1f37f2f7466996529d8efaa873abf93592ec69d768d10ab37f01ef7d6c5d3af86a5011f3f61204ebd44c3
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
|
3
|
+
require 'webpack_stats/version'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module WebpackStats
|
7
|
+
REGEXP = /(.+?)(?:-([0-9a-f]{20,}))?\.(\w+)/
|
8
|
+
|
9
|
+
@reload = defined?(::Rails) && ::Rails.env.production? ? false : true
|
10
|
+
@stats_path = defined?(::Rails) ? ::Rails.root.join('stats.json') : 'stats.json'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :reload, :stats_path, :splitter
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
|
19
|
+
def assets
|
20
|
+
@reload ? load_assets : @assets ||= load_assets
|
21
|
+
end
|
22
|
+
|
23
|
+
def stats
|
24
|
+
@reload ? load_stats : @stats ||= load_stats
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_stats
|
28
|
+
JSON.parse File.read @stats_path
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_assets
|
32
|
+
ret = {}
|
33
|
+
_stats = stats
|
34
|
+
_stats['assets'].each do |asset|
|
35
|
+
key, value = split_asset_name(_stats, asset['name'])
|
36
|
+
ret[key] = value
|
37
|
+
end
|
38
|
+
ret
|
39
|
+
end
|
40
|
+
|
41
|
+
def split_asset_name stats, asset_name
|
42
|
+
if @splitter.respond_to? :call
|
43
|
+
@splitter.call stats['publicPath'], asset_name
|
44
|
+
else
|
45
|
+
full_name, name, hash, ext = REGEXP.match(asset_name).to_a
|
46
|
+
["#{name}.#{ext}", File.join(stats['publicPath'], full_name)]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
if defined? ::Rails
|
53
|
+
module Helper
|
54
|
+
def compute_asset_path source, options = {}
|
55
|
+
WebpackStats.assets[source] || super
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if defined? ::ActiveSupport
|
63
|
+
ActiveSupport.on_load(:action_view) do
|
64
|
+
include WebpackStats::Helper
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webpack_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jian Weihang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.8'
|
69
|
+
description: Webpack Stats loader for Rails
|
70
|
+
email: tonytonyjan@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/webpack_stats.rb
|
76
|
+
homepage: https://github.com/tonytonyjan/webpack_stats
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.5.1
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Webpack Stats loader for Rails
|
100
|
+
test_files: []
|