When calling bin/magento static-content:deploy
this gets called:
\Magento\Deploy\Console\Command\DeployStaticContentCommand::execute()
This method calls
$deployer = $this->objectManager->create(
'Magento\Deploy\Model\Deployer',
['filesUtil' => $filesUtil, 'output' => $output, 'isDryRun' => $options[self::DRY_RUN_OPTION]]
);
$deployer->deploy($this->objectManagerFactory, $languages);
which translates to \Magento\Deploy\Model\Deployer::deploy
. At the bottom of this method you will find
foreach ($this->filesUtil->getPhtmlFiles(false, false) as $template) {
$this->htmlMinifier->minify($template);
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->output->writeln($template . " minified\n");
} else {
$this->output->write('.');
}
$this->count++;
}
If you want you can dig deeper in \Magento\Framework\App\Utility::getPhtmlFiles
to see how the templates are retrieved.
Short version:
It calls accumulateModuleTemplateFiles
and accumulateThemeTemplateFiles
from the same class. These methods are using (in the end) glob
and some regular expressions to retrieve all the template files from the modules and from the themes and minifying is done by \Magento\Framework\View\Template\Html\Minifier
(that implements \Magento\Framework\View\Template\Html\MinifierInterface
) based on some strange regular expressions. (see minify
method).
The thing I don't know yet, it how are these templates loaded for use. most probably they are loaded by the template engine. I will post back here if/when I find that.
[EDIT]
I found when the minified templates are used. When you set the value for Store->Configuration->Developer->Template Settings->Minify HTML
to Yes
and when on production mode.