Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\State;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;

class Config extends AbstractHelper {

Expand All @@ -18,6 +19,7 @@ class Config extends AbstractHelper {
* @var State
*/
protected State $state;
private array $allowModuleNames;

/**
* @param Context $context
Expand All @@ -27,28 +29,28 @@ class Config extends AbstractHelper {
public function __construct(
Context $context,
RequestInterface $request,
State $state
State $state,
array $allowModuleNames = []
) {
$this->request = $request;
$this->state = $state;
return parent::__construct($context);
$this->allowModuleNames = $allowModuleNames;
parent::__construct($context);
}

public function optimizeRequireJsConfig() {
try {
$areaCode = $this->state->getAreaCode();
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$areaCode = 'cli';
} catch (LocalizedException $e) {
return true;
}

if (
$areaCode === 'cli' ||
$areaCode === 'frontend' &&
($this->request->getModuleName() === "cms" || $this->request->getModuleName() === "catalog")
if ($areaCode === 'frontend'
&& in_array($this->request->getModuleName(), $this->allowModuleNames)
) {
return true;
}

return false;
}

}
8 changes: 8 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@
<type name="Magento\Framework\RequireJs\Config">
<plugin name="use-optimized-requirejs-build" type="MageOS\RequireJsOptimizer\Plugin\ChangeRequireJsConfig" />
</type>
<type name="MageOS\RequireJsOptimizer\Helper\Config">
<arguments>
<argument name="allowModuleNames" xsi:type="array">
<item name="cms" xsi:type="string">cms</item>
<item name="catalog" xsi:type="string">catalog</item>
</argument>
</arguments>
</type>
</config>