Sur la base du commentaire @Arshad M, vous pouvez ajouter un di.xml avec:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\RequireJs\Config" type="<Vendor>\<ModuleName>\RequireJs\Config"/>
</config>
Et dans <Vendor> \ <ModuleName> \ RequireJs \ Config.php, remplacez la fonction getConfig en ajoutant votre condition et le nom du module que vous ne voulez pas que les requirejs soient chargés (probablement depuis ScopeConfigInterface):
<?php
namespace <Vendor>\<ModuleName>\RequireJs;
use Magento\Framework\Filesystem\File\ReadFactory;
use Magento\Framework\View\Asset\Minification;
use Magento\Framework\View\Asset\RepositoryMap;
class Config extends \Magento\Framework\RequireJs\Config
{
/**
* @var \Magento\Framework\RequireJs\Config\File\Collector\Aggregated
*/
private $fileSource;
/**
* @var ReadFactory
*/
private $readFactory;
/**
* @var \Magento\Framework\Code\Minifier\AdapterInterface
*/
private $minifyAdapter;
/**
* @var Minification
*/
private $minification;
/**
* @var \Magento\Framework\View\DesignInterface
*/
private $design;
public function __construct(\Magento\Framework\RequireJs\Config\File\Collector\Aggregated $fileSource, \Magento\Framework\View\DesignInterface $design, ReadFactory $readFactory, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\Code\Minifier\AdapterInterface $minifyAdapter, Minification $minification, RepositoryMap $repositoryMap)
{
parent::__construct($fileSource, $design, $readFactory, $assetRepo, $minifyAdapter, $minification, $repositoryMap);
$this->fileSource = $fileSource;
$this->readFactory = $readFactory;
$this->minifyAdapter = $minifyAdapter;
$this->minification = $minification;
$this->design = $design;
}
public function getConfig()
{
$distributedConfig = '';
$customConfigFiles = $this->fileSource->getFiles($this->design->getDesignTheme(), self::CONFIG_FILE_NAME);
foreach ($customConfigFiles as $file) {
//Your condition
if(true){
if($file->getModule() == "Vendor_ModuleName"){
continue;
}
}
/** @var $fileReader \Magento\Framework\Filesystem\File\Read */
$fileReader = $this->readFactory->create($file->getFileName(), \Magento\Framework\Filesystem\DriverPool::FILE);
$config = $fileReader->readAll($file->getName());
$distributedConfig .= str_replace(
['%config%', '%context%'],
[$config, $file->getModule()],
self::PARTIAL_CONFIG_TEMPLATE
);
}
$fullConfig = str_replace(
['%function%', '%usages%'],
[$distributedConfig],
self::FULL_CONFIG_TEMPLATE
);
if ($this->minification->isEnabled('js')) {
$fullConfig = $this->minifyAdapter->minify($fullConfig);
}
return $fullConfig;
}
}
MISE À JOUR
Après les commentaires de @Alex et @Daniel: Vous pouvez créer un plugin after pour getFiles à partir de Magento \ Framework \ RequireJs \ Config \ File \ Collector \ Aggregated, donc le nouveau di.xml avec cette approche serait:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\RequireJs\Config\File\Collector\Aggregated">
<plugin name="requirejsConfigPlugin"
type="<Vendor>\<ModuleName>\Plugin\RequireJs\AfterFiles"
sortOrder="100"
/>
</type>
</config>
Et dans \ <Vendor> \ <ModuleName> \ Plugin \ RequireJs \ AfterFiles, vous pouvez définir votre condition et votre module pour que le requirejs ne soit pas chargé:
<?php
namespace <Vendor>\<ModuleName>\Plugin\RequireJs;
class AfterFiles
{
public function afterGetFiles(
\Magento\Framework\RequireJs\Config\File\Collector\Aggregated $subject,
$result
){
//Your condition
if(true) {
foreach ($result as $key => &$file) {
//Module to exclude
if ($file->getModule() == "Vendor_OtherModuleName") {
unset($result[$key]);
}
}
}
return $result;
}
}