Skip to content

Commit 89a59a3

Browse files
committed
Added custom_compile setting
Provide an easy way to tell webpacker that we have a custom compile operation, such as used by react on rails.
1 parent ca3b046 commit 89a59a3

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

lib/install/config/webpacker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ default: &default
55
source_entry_path: packs
66
public_output_path: packs
77
cache_path: tmp/cache/webpacker
8+
custom_compile: false
89

910
# Additional paths webpack should lookup modules
1011
# ['app/assets', 'engine/foo/app/assets']

lib/tasks/webpacker/check_binstubs.rake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
namespace :webpacker do
22
desc "Verifies that bin/webpack & bin/webpack-dev-server are present."
33
task :check_binstubs do
4-
unless File.exist?("bin/webpack") && File.exist?("bin/webpack-dev-server")
4+
unless Webpacker.config.custom_compile? ||
5+
(File.exist?("bin/webpack") && File.exist?("bin/webpack-dev-server"))
56
$stderr.puts "Webpack binstubs not found.\n"\
67
"Have you run rails webpacker:install ?\n"\
78
"Make sure the bin directory or binstubs are not included in .gitignore\n"\

lib/tasks/webpacker/verify_install.rake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ require "webpacker/configuration"
33
namespace :webpacker do
44
desc "Verifies if webpacker is installed"
55
task verify_install: [:check_node, :check_yarn, :check_binstubs] do
6-
if Webpacker.config.config_path.exist?
7-
$stdout.puts "Webpacker is installed 🎉 🍰"
8-
$stdout.puts "Using #{Webpacker.config.config_path} file for setting up webpack paths"
9-
else
10-
$stderr.puts "Configuration config/webpacker.yml file not found. \n"\
6+
unless Webpacker.config.custom_compile?
7+
if Webpacker.config.config_path.exist?
8+
$stdout.puts "Webpacker is installed 🎉 🍰"
9+
$stdout.puts "Using #{Webpacker.config.config_path} file for setting up webpack paths"
10+
else
11+
$stderr.puts "Configuration config/webpacker.yml file not found. \n"\
1112
"Make sure webpacker:install is run successfully before " \
1213
"running dependent tasks"
13-
exit!
14+
exit!
15+
end
1416
end
1517
end
1618
end

lib/webpacker/configuration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ def compile?
1717
fetch(:compile)
1818
end
1919

20+
def custom_compile?
21+
fetch(:custom_compile)
22+
end
23+
2024
def source_path
2125
root_path.join(fetch(:source_path))
2226
end

lib/webpacker/manifest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def find(name)
4242

4343
def handle_missing_entry(name)
4444
raise Webpacker::Manifest::MissingEntryError,
45-
"Can't find #{name} in #{config.public_manifest_path}. Manifest contains: #{@data}"
45+
"Can't find #{name} in #{config.public_manifest_path}. Manifest contains:\n#{JSON.pretty_generate(@data)}"
4646
end
4747

4848
def missing_file_from_manifest_error(bundle_name)

test/manifest_test.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ def test_lookup_exception
99
error = assert_raises Webpacker::Manifest::MissingEntryError do
1010
Webpacker.manifest.lookup(asset_file)
1111
end
12+
expected = <<-MSG.strip
13+
Can't find calendar.js in #{manifest_path}. Manifest contains:
14+
{
15+
"bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css",
16+
"application.css": "/packs/application-dd6b1cd38bfa093df600.css",
17+
"bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
18+
"application.js": "/packs/application-k344a6d59eef8632c9d1.js"
19+
}
20+
MSG
1221

13-
assert_equal "Can't find #{asset_file} in #{manifest_path}. Is webpack still compiling?", error.message
22+
assert_equal expected, error.message
1423
end
1524
end
1625

0 commit comments

Comments
 (0)