Com base no comentário do @Arshad M, você pode adicionar um di.xml com:
<?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>
E em <Fornecedor> \ <ModuleName> \ RequireJs \ Config.php, substitua a função getConfig, adicionando sua condição e o nome do módulo que você não deseja que os requirejs sejam carregados (provavelmente de 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;
}
}
ATUALIZAR
Após comentários de @Alex e @Daniel: Você pode criar um plug-in pós-getFiles a partir de Magento \ Framework \ RequireJs \ Config \ File \ Collector \ Aggregated, para que o novo di.xml com essa abordagem seja:
<?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>
E em \ <Fornecedor> \ <Nome do Módulo> \ Plugin \ RequireJs \ AfterFiles, você pode definir sua condição e módulo para que os requirejs não sejam carregados:
<?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;
}
}