Skip to content

Commit

Permalink
Faster manifest loading on devServer (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
martenb authored May 31, 2021
1 parent 34b0a5d commit 11d1f10
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Manifest/ManifestLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,39 @@ public function __construct(BuildDirectoryProvider $directoryProvider, ManifestM
public function loadManifest(string $fileName): array
{
$path = $this->getManifestPath($fileName);
$context = \stream_context_create(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]); // webpack-dev-server uses self-signed certificate
$manifest = @\file_get_contents($path, false, $context); // @ - errors handled by custom exception

if (\is_file($path)) {
$manifest = @\file_get_contents($path); // @ - errors handled by custom exception
} else {
$ch = \curl_init($path);

if ($ch === false) {
$manifest = false;
} else {
\curl_setopt_array($ch, [
\CURLOPT_RETURNTRANSFER => true,
\CURLOPT_FAILONERROR => true,

// allow self-signed certificates
\CURLOPT_SSL_VERIFYHOST => 0,
\CURLOPT_SSL_VERIFYPEER => false,
]);
/** @var string|false $manifest */
$manifest = \curl_exec($ch);

if ($manifest === false) {
$errorMessage = \curl_error($ch);
}

\curl_close($ch);
}
}

if ($manifest === false) {
throw new CannotLoadManifestException(\sprintf(
"Manifest file '%s' could not be loaded: %s",
$path,
\error_get_last()['message'] ?? 'unknown error'
$errorMessage ?? (\error_get_last()['message'] ?? 'unknown error')
));
}

Expand Down

0 comments on commit 11d1f10

Please sign in to comment.