config = $config; $this->fileManager = $fileManager; $this->pageConfig = $pageConfig; $this->bundleConfig = $bundleConfig; $this->minification = $minification; } /** * Include RequireJs configuration as an asset on the page * * @return $this */ protected function _prepareLayout() { $requireJsConfig = $this->fileManager->createRequireJsConfigAsset(); $requireJsMixinsConfig = $this->fileManager->createRequireJsMixinsAsset(); $assetCollection = $this->pageConfig->getAssetCollection(); $after = RequireJsConfig::REQUIRE_JS_FILE_NAME; if ($this->minification->isEnabled('js')) { $minResolver = $this->fileManager->createMinResolverAsset(); $assetCollection->insert( $minResolver->getFilePath(), $minResolver, $after ); $after = $minResolver->getFilePath(); } if ($this->bundleConfig->isBundlingJsFiles()) { $bundleAssets = $this->fileManager->createBundleJsPool(); $staticAsset = $this->fileManager->createStaticJsAsset(); /** @var \Magento\Framework\View\Asset\File $bundleAsset */ if (!empty($bundleAssets) && $staticAsset !== false) { $bundleAssets = array_reverse($bundleAssets); foreach ($bundleAssets as $bundleAsset) { $assetCollection->insert( $bundleAsset->getFilePath(), $bundleAsset, $after ); } $assetCollection->insert( $staticAsset->getFilePath(), $staticAsset, reset($bundleAssets)->getFilePath() ); $after = $staticAsset->getFilePath(); } } $assetCollection->insert( $requireJsConfig->getFilePath(), $requireJsConfig, $after ); $assetCollection->insert( $requireJsMixinsConfig->getFilePath(), $requireJsMixinsConfig, $after ); return parent::_prepareLayout(); } }