예제 #1
0
 /**
  * @return string
  */
 public function compile()
 {
     $this->stopwatch->start('webpack.total');
     $this->stopwatch->start('webpack.prepare');
     // Recompile twig templates where its needed.
     $this->addSplitPoints();
     $this->addResolveConfig();
     // Write the webpack configuration file.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.config.js', $this->generator->getConfiguration());
     $this->profiler->set('compiler.performance.prepare', $this->stopwatch->stop('webpack.prepare')->getDuration());
     $this->stopwatch->start('webpack.compiler');
     $this->process->run();
     $output = $this->process->getOutput() . $this->process->getErrorOutput();
     $this->profiler->set('compiler.executed', true);
     $this->profiler->set('compiler.successful', strpos($output, 'Error:') === false);
     $this->profiler->set('compiler.last_output', $output);
     if ($this->profiler->get('compiler.successful')) {
         $this->tracker->rebuild();
     }
     // Finally, write some logging for later use.
     file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . 'webpack.compiler.log', $output);
     $this->profiler->set('compiler.performance.compiler', $this->stopwatch->stop('webpack.compiler')->getDuration());
     $this->profiler->set('compiler.performance.total', $this->stopwatch->stop('webpack.total')->getDuration());
     return $output;
 }
예제 #2
0
 public function testBuild()
 {
     $config = new ConfigGenerator();
     $config->addBlock((new CodeBlock())->set(CodeBlock::HEADER, 'var a = require("b");'))->addBlock((new CodeBlock())->set(CodeBlock::ENTRY, ['a' => '/path/to/a.js']))->addBlock((new CodeBlock())->set(CodeBlock::ENTRY, ['b' => '/path/to/b.js']))->addBlock((new CodeBlock())->set(CodeBlock::OUTPUT, ['a' => 'a']))->addBlock((new CodeBlock())->set(CodeBlock::OUTPUT, ['b' => 'b', 'c' => 'c']))->addBlock((new CodeBlock())->set(CodeBlock::RESOLVE, ['root' => ['a' => 'b']]))->addBlock((new CodeBlock())->set(CodeBlock::RESOLVE, ['root' => ['b' => 'c']]))->addBlock((new CodeBlock())->set(CodeBlock::RESOLVE, ['alias' => ['a' => 'b', 'b' => 'c']]))->addBlock((new CodeBlock())->set(CodeBlock::RESOLVE, ['alias' => ['c' => 'a']]))->addBlock((new CodeBlock())->set(CodeBlock::RESOLVE_LOADER, ['root' => '/path/to/node_modules']));
     // Add loaders...
     $config->addBlock((new CodeBlock())->set(CodeBlock::LOADER, '{ test: /\\.css$/, loader: "style!some-loader" }'));
     $config->addBlock((new CodeBlock())->set(CodeBlock::POST_LOADER, '{ test: /\\.inl$/, loader: "style" }'));
     $config->addBlock((new CodeBlock())->set(CodeBlock::HEADER, 'var preLoader1 = require("pre-loader-1");')->set(CodeBlock::PRE_LOADER, '{ test: /\\.css$/, loader: preLoader1.execute("a", "b") }'));
     $config->addBlock((new CodeBlock())->set(CodeBlock::HEADER, 'var preLoader2 = require("pre-loader-2");')->set(CodeBlock::PRE_LOADER, '{ test: /\\.less$/, loader: preLoader2.execute("c", "d") }'));
     // And some plugins
     $config->addBlock((new DefinePlugin(['plugins' => ['constants' => ['a' => 'b']]]))->add('b', 'c')->getCodeBlocks()[0]);
     $config->addBlock((new DefinePlugin(['plugins' => ['constants' => ['c' => 'd']]]))->add('d', 'e')->getCodeBlocks()[0]);
     // Add extension
     $config->addExtension(new OutputConfig(['output' => ['path' => 'path/to/output']]));
     $config->addExtension(new CSSLoader(['loaders' => ['css' => ['enabled' => true, 'filename' => 'foo', 'all_chunks' => true]]]));
     $fixture_file = __DIR__ . '/../../Fixture/Component/Configuration/ConfigGenerator.js';
     // file_put_contents($fixture_file, $config->getConfiguration());
     $fixture = file_get_contents($fixture_file);
     $this->assertEquals(str_replace("\r\n", "\n", $fixture), str_replace("\r\n", "\n", $config->getConfiguration()));
 }