@Arshad M 주석을 기반으로 다음을 사용하여 di.xml을 추가 할 수 있습니다.
<?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>
그리고 <Vendor> \ <ModuleName> \ RequireJs \ Config.php에서 getConfig 함수를 재정 의하여 requirejs를로드하지 않으려는 모듈 이름과 조건을 추가하십시오 (아마도 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;
}
}
최신 정보
@Alex 및 @Daniel의 주석 후 : Magento \ Framework \ RequireJs \ Config \ File \ Collector \ Aggregated에서 getFiles에 대한 플러그인을 만들 수 있으므로이 접근법을 사용하는 새로운 di.xml은 다음과 같습니다.
<?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>
\ <Vendor> \ <ModuleName> \ Plugin \ RequireJs \ AfterFiles에서 requirejs가로드되지 않도록 조건과 모듈을 설정할 수 있습니다.
<?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;
}
}