Sha256: 2f3f5b6c530c59e0964d54140b94fef02f79346786468d0e9ddf8795a6e4d9ed
Contents?: true
Size: 1.07 KB
Versions: 5
Compression:
Stored size: 1.07 KB
Contents
require "open-uri" module React module ServerRendering # Get a compiled file from Webpacker. It may come from: # # - webpack-dev-server # - compiled pack class WebpackerManifestContainer # This pattern matches the code that initializes the dev-server client. CLIENT_REQUIRE = %r{__webpack_require__\(.*webpack-dev-server\/client\/index\.js.*\n} def find_asset(logical_path) # raises if not found asset_path = Webpacker::Manifest.lookup(logical_path).to_s if asset_path.start_with?("http") # Get a file from the webpack-dev-server dev_server_asset = open(asset_path).read # Remove `webpack-dev-server/client/index.js` code which causes ExecJS to 💥 dev_server_asset.sub!(CLIENT_REQUIRE, '//\0') dev_server_asset else # Read the already-compiled pack: full_path = Webpacker::Manifest.lookup_path(logical_path).to_s File.read(full_path) end end def self.compatible? !!defined?(Webpacker) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems