-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
configuration.rb
105 lines (81 loc) · 2.11 KB
/
configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require "yaml"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/hash/indifferent_access"
class Webpacker::Configuration
attr_reader :root_path, :config_path, :env
def initialize(root_path:, config_path:, env:)
@root_path = root_path
@config_path = config_path
@env = env
end
def dev_server
fetch(:dev_server)
end
def compile?
fetch(:compile)
end
def source_path
root_path.join(fetch(:source_path))
end
def resolved_paths
fetch(:resolved_paths)
end
def resolved_paths_globbed
resolved_paths.map { |p| "#{p}/**/*" }
end
def source_entry_path
source_path.join(fetch(:source_entry_path))
end
def public_path
root_path.join("public")
end
def public_output_path
public_path.join(fetch(:public_output_path))
end
def public_manifest_path
public_output_path.join("manifest.json")
end
def cache_manifest?
fetch(:cache_manifest)
end
def cache_path
root_path.join(fetch(:cache_path))
end
def extensions
fetch(:extensions)
end
def check_yarn_integrity=(value)
data[:check_yarn_integrity] = value
end
def check_yarn_integrity?
fetch(:check_yarn_integrity)
end
def webpack_compile_output?
fetch(:webpack_compile_output)
end
def extract_css?
fetch(:extract_css)
end
private
def fetch(key)
data.fetch(key, defaults[key])
end
def data
@data ||= load
end
def load
YAML.load(config_path.read)[env].deep_symbolize_keys
rescue Errno::ENOENT => e
raise "Webpacker configuration file not found #{config_path}. " \
"Please run rails webpacker:install " \
"Error: #{e.message}"
rescue Psych::SyntaxError => e
raise "YAML syntax error occurred while parsing #{config_path}. " \
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
"Error: #{e.message}"
end
def defaults
@defaults ||= \
HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env])
end
end