Class: Shakapacker::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/shakapacker/configuration.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path:, config_path:, env:) ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
17
# File 'lib/shakapacker/configuration.rb', line 13

def initialize(root_path:, config_path:, env:)
  @root_path = root_path
  @env = env
  @config_path = config_path
end

Class Attribute Details

.installingObject

Returns the value of attribute installing.



8
9
10
# File 'lib/shakapacker/configuration.rb', line 8

def installing
  @installing
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



11
12
13
# File 'lib/shakapacker/configuration.rb', line 11

def config_path
  @config_path
end

#envObject (readonly)

Returns the value of attribute env.



11
12
13
# File 'lib/shakapacker/configuration.rb', line 11

def env
  @env
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



11
12
13
# File 'lib/shakapacker/configuration.rb', line 11

def root_path
  @root_path
end

Instance Method Details

#additional_pathsObject



48
49
50
# File 'lib/shakapacker/configuration.rb', line 48

def additional_paths
  fetch(:additional_paths)
end

#asset_hostObject



204
205
206
207
208
209
# File 'lib/shakapacker/configuration.rb', line 204

def asset_host
  ENV.fetch(
    "SHAKAPACKER_ASSET_HOST",
    fetch(:asset_host) || ActionController::Base.helpers.compute_asset_host
  )
end

#assets_bundlerObject



99
100
101
102
103
104
105
# File 'lib/shakapacker/configuration.rb', line 99

def assets_bundler
  # Show deprecation warning if using old 'bundler' key
  if data.has_key?(:bundler) && !data.has_key?(:assets_bundler)
    $stderr.puts "⚠️  DEPRECATION WARNING: The 'bundler' configuration option is deprecated. Please use 'assets_bundler' instead to avoid confusion with Ruby's Bundler gem manager."
  end
  ENV["SHAKAPACKER_ASSETS_BUNDLER"] || fetch(:assets_bundler) || fetch(:bundler) || "webpack"
end

#bundlerObject

Deprecated: Use assets_bundler instead



108
109
110
# File 'lib/shakapacker/configuration.rb', line 108

def bundler
  assets_bundler
end

#cache_manifest?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/shakapacker/configuration.rb', line 83

def cache_manifest?
  fetch(:cache_manifest)
end

#cache_pathObject



87
88
89
# File 'lib/shakapacker/configuration.rb', line 87

def cache_path
  root_path.join(fetch(:cache_path))
end

#compile?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/shakapacker/configuration.rb', line 23

def compile?
  fetch(:compile)
end

#compiler_strategyObject



95
96
97
# File 'lib/shakapacker/configuration.rb', line 95

def compiler_strategy
  fetch(:compiler_strategy)
end

#dev_serverObject



19
20
21
# File 'lib/shakapacker/configuration.rb', line 19

def dev_server
  fetch(:dev_server)
end

#ensure_consistent_versioning?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/shakapacker/configuration.rb', line 31

def ensure_consistent_versioning?
  fetch(:ensure_consistent_versioning)
end

#fetch(key) ⇒ Object



200
201
202
# File 'lib/shakapacker/configuration.rb', line 200

def fetch(key)
  data.fetch(key, defaults[key])
end

#integrityObject



211
212
213
# File 'lib/shakapacker/configuration.rb', line 211

def integrity
  fetch(:integrity)
end

#javascript_transpilerObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/shakapacker/configuration.rb', line 120

def javascript_transpiler
  # Show deprecation warning if using old 'webpack_loader' key
  if data.has_key?(:webpack_loader) && !data.has_key?(:javascript_transpiler)
    $stderr.puts "⚠️  DEPRECATION WARNING: The 'webpack_loader' configuration option is deprecated. Please use 'javascript_transpiler' instead as it better reflects its purpose of configuring JavaScript transpilation regardless of the bundler used."
  end

  # Use explicit config if set, otherwise default based on bundler
  transpiler = fetch(:javascript_transpiler) || fetch(:webpack_loader) || default_javascript_transpiler

  # Validate transpiler configuration
  validate_transpiler_configuration(transpiler) unless self.class.installing

  transpiler
end

#manifest_pathObject



56
57
58
59
60
61
62
# File 'lib/shakapacker/configuration.rb', line 56

def manifest_path
  if data.has_key?(:manifest_path)
    root_path.join(fetch(:manifest_path))
  else
    public_output_path.join("manifest.json")
  end
end

#nested_entries?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/shakapacker/configuration.rb', line 27

def nested_entries?
  fetch(:nested_entries)
end

#private_output_pathObject



72
73
74
75
76
77
# File 'lib/shakapacker/configuration.rb', line 72

def private_output_path
  private_path = fetch(:private_output_path)
  return nil unless private_path
  validate_output_paths!
  root_path.join(private_path)
end

#public_manifest_pathObject



64
65
66
# File 'lib/shakapacker/configuration.rb', line 64

def public_manifest_path
  manifest_path
end

#public_output_pathObject



79
80
81
# File 'lib/shakapacker/configuration.rb', line 79

def public_output_path
  public_path.join(fetch(:public_output_path))
end

#public_pathObject



68
69
70
# File 'lib/shakapacker/configuration.rb', line 68

def public_path
  root_path.join(fetch(:public_root_path))
end

#rspack?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/shakapacker/configuration.rb', line 112

def rspack?
  assets_bundler == "rspack"
end

#shakapacker_precompile?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/shakapacker/configuration.rb', line 35

def shakapacker_precompile?
  # ENV of false takes precedence
  return false if %w(no false n f).include?(ENV["SHAKAPACKER_PRECOMPILE"])
  return true if %w(yes true y t).include?(ENV["SHAKAPACKER_PRECOMPILE"])

  return false unless config_path.exist?
  fetch(:shakapacker_precompile)
end

#source_entry_pathObject



52
53
54
# File 'lib/shakapacker/configuration.rb', line 52

def source_entry_path
  source_path.join(relative_path(fetch(:source_entry_path)))
end

#source_pathObject



44
45
46
# File 'lib/shakapacker/configuration.rb', line 44

def source_path
  root_path.join(fetch(:source_path))
end

#webpack?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/shakapacker/configuration.rb', line 116

def webpack?
  assets_bundler == "webpack"
end

#webpack_compile_output?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/shakapacker/configuration.rb', line 91

def webpack_compile_output?
  fetch(:webpack_compile_output)
end

#webpack_loaderObject

Deprecated: Use javascript_transpiler instead



136
137
138
# File 'lib/shakapacker/configuration.rb', line 136

def webpack_loader
  javascript_transpiler
end