Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function generate($uri, $alias = null)
 {
     $html = $this->htmlFetcher->fetch($uri);
     $builder = new ProcessBuilder();
     $builder->setPrefix($this->criticalBin);
     $builder->setArguments(['--base=' . realpath(__DIR__ . '/../.tmp'), '--width=' . $this->width, '--height=' . $this->height, '--minify']);
     foreach ($this->css as $css) {
         $builder->add('--css=' . $css);
     }
     foreach ($this->ignore as $ignore) {
         $builder->add('--ignore=' . $ignore);
     }
     $builder->setInput($html);
     $process = $builder->getProcess();
     $process->run();
     if (!$process->isSuccessful()) {
         throw new CssGeneratorException(sprintf('Error processing URI [%s]. This is probably caused by ' . 'the Critical npm package. Checklist: 1) `critical_bin`' . ' is correct, 2) `css` paths are correct 3) run `npm ' . 'install` again.', $uri));
     }
     return $this->storage->writeCss(is_null($alias) ? $uri : $alias, $process->getOutput());
 }
Exemplo n.º 2
0
 /**
  * Remove old critical-path CSS.
  *
  * @return void
  */
 protected function removeOldCss()
 {
     $this->info('Removing old critical-path CSS.');
     $this->storage->clearCss();
 }