Skip to content

Commit

Permalink
Allow loading webpack.config.ts if present
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother committed Oct 29, 2024
1 parent a59be7d commit 3d1dbac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/shakapacker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@ def initialize(argv)
@argv = argv

@app_path = File.expand_path(".", Dir.pwd)
@webpack_config = File.join(@app_path, "config/webpack/webpack.config.js")
@shakapacker_config = ENV["SHAKAPACKER_CONFIG"] || File.join(@app_path, "config/shakapacker.yml")

unless File.exist?(@webpack_config)
$stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or add the missing config file for your custom environment."
exit!
end
@webpack_config = find_webpack_config

Shakapacker::Utils::Manager.error_unless_package_manager_is_obvious!
end

def package_json
@package_json ||= PackageJson.read(@app_path)
end

private

def find_webpack_config
possible_paths = %w[ts js].map do |ext|
File.join(@app_path, "config/webpack/webpack.config.#{ext}")
end
path = possible_paths.select { |f| File.exist?(f) }.first
unless path
$stderr.puts "webpack config #{possible_paths.last} not found, please run 'bundle exec rails shakapacker:install' to install Shakapacker with default configs or add the missing config file for your custom environment."
exit!
end
path
end
end
end
11 changes: 11 additions & 0 deletions spec/shakapacker/webpack_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@

verify_command(cmd, argv: (["--watch"]))
end

it "loads webpack.config.ts if present" do
ts_config = "#{test_app_path}/config/webpack/webpack.config.ts"
FileUtils.touch(ts_config)

cmd = package_json.manager.native_exec_command("webpack", ["--config", ts_config])

verify_command(cmd)
ensure
FileUtils.rm(ts_config)
end
end
end

Expand Down

0 comments on commit 3d1dbac

Please sign in to comment.