@@ -22,19 +22,33 @@ def self.compatible?
2222 !!defined? ( Webpacker )
2323 end
2424
25- def find_asset ( logical_path )
26- # raises if not found
27- asset_path = manifest . lookup ( logical_path ) . to_s
28- if asset_path . start_with? ( "http" )
29- # Get a file from the webpack-dev-server
30- dev_server_asset = open ( asset_path ) . read
31- # Remove `webpack-dev-server/client/index.js` code which causes ExecJS to 💥
32- dev_server_asset . sub! ( CLIENT_REQUIRE , '//\0' )
33- dev_server_asset
34- else
35- # Read the already-compiled pack:
36- full_path = file_path ( logical_path ) . to_s
37- File . read ( full_path )
25+ if MAJOR < 3
26+ def find_asset ( logical_path )
27+ # raises if not found
28+ asset_path = manifest . lookup ( logical_path ) . to_s
29+ if asset_path . start_with? ( "http" )
30+ # Get a file from the webpack-dev-server
31+ dev_server_asset = open ( asset_path ) . read
32+ # Remove `webpack-dev-server/client/index.js` code which causes ExecJS to 💥
33+ dev_server_asset . sub! ( CLIENT_REQUIRE , '//\0' )
34+ dev_server_asset
35+ else
36+ # Read the already-compiled pack:
37+ full_path = file_path ( logical_path ) . to_s
38+ File . read ( full_path )
39+ end
40+ end
41+ else
42+ def find_asset ( logical_path )
43+ asset_path = Webpacker . manifest . lookup ( logical_path ) . to_s
44+ if Webpacker . dev_server . running?
45+ ds = Webpacker . dev_server
46+ dev_server_asset = open ( "#{ ds . protocol } ://#{ ds . host_with_port } #{ asset_path } " ) . read
47+ dev_server_asset . sub! ( CLIENT_REQUIRE , '//\0' )
48+ dev_server_asset
49+ else
50+ File . read ( file_path ( logical_path ) )
51+ end
3852 end
3953 end
4054
0 commit comments