20

The Magento 2 "blank" theme includes the following tag hierarchy.

<exclude>
    <item type="file">Lib::jquery/jquery-ui-1.9.2.js</item>
    <item type="file">Lib::jquery/jquery.ba-hashchange.min.js</item>
    <item type="file">Lib::jquery/jquery.details.js</item>
    <item type="file">Lib::jquery/jquery.details.min.js</item>
    <item type="file">Lib::jquery/jquery.hoverIntent.js</item>
    <item type="file">Lib::jquery/jquery.min.js</item>
    <item type="file">Lib::mage/captcha.js</item>
    <item type="file">Lib::mage/dropdown_old.js</item>
    <item type="file">Lib::mage/list.js</item>
    <item type="file">Lib::mage/loader_old.js</item>
    <item type="file">Lib::mage/webapi.js</item>
    <item type="file">Lib::moment.js</item>
    <item type="file">Lib::requirejs/require.js</item>
    <item type="file">Lib::date-format-normalizer.js</item>
    <item type="file">Lib::legacy-build.min.js</item>
    <item type="directory">Lib::modernizr</item>
    <item type="directory">Lib::tiny_mce</item>
    <item type="directory">Lib::varien</item>
    <item type="directory">Lib::jquery/editableMultiselect</item>
    <item type="directory">Lib::jquery/jstree</item>
    <item type="directory">Lib::jquery/fileUploader</item>
    <item type="directory">Lib::css</item>
    <item type="directory">Lib::lib</item>
    <item type="directory">Lib::extjs</item>
    <item type="directory">Lib::prototype</item>
    <item type="directory">Lib::scriptaculous</item>
    <item type="directory">Lib::mage/requirejs</item>
    <item type="directory">Lib::mage/adminhtml</item>
    <item type="directory">Lib::mage/backend</item>
    <item type="directory">Magento_Swagger::swagger-ui</item>
</exclude>

What is this here for. i.e. what's being excluded from what? Where and when does Magento 2 system code access this information?

2
  • 6
    It's evaluated in the same place where we excluded you from this information, Alan.
    – benmarks
    Jan 8, 2016 at 21:37
  • 7
    @benmarks Being excluded from the implementation details of a particular system makes me feel closer to most employees of Magento Inc. ;) Jan 8, 2016 at 21:55

2 Answers 2

12

Magento 2 supported bundling of js/html files. <exclude> node define list of resources that should not be bundled. see \Magento\Framework\View\Asset\Bundle\Manager for details

5
  • 2
    Bundling? What does that mean? Magento supports a ruby package manager? Jan 15, 2016 at 20:07
  • 1
    'Bundling' means combining multiple resources into a single package/file. It is frontend performance improvement by decreasing quantity of request to server.
    – KAndy
    Jan 15, 2016 at 20:12
  • Which bundling does exclude apply to? There seem to be multiple places Magento "bundles up" frontend assets. Jan 15, 2016 at 20:19
  • I'm guessing if it's a .js file, it'll load that individually. If it isn't excluded, it'll be merged in a JS file like we're used to with the JS Merge option in M1. If a dir is excluded, all files in that dir will be loaded individually. Jan 25, 2016 at 20:27
  • Update; this method confirms my suspicion; github.com/magento/magento2/blob/… Jan 25, 2016 at 20:33
11

This configuration is accessed when you execute the command

bin/magento setup:static-content:deploy

In the function \Magento\Deploy\Model\Deployer::deployFile, the following two calls are of interest:

$this->assetPublisher->publish($asset);
$this->bundleManager->addAsset($asset);

The first call will add the asset file to the filesystem. I'm not sure what the second call does exactly. That's where I'm getting lost.

However, if you follow this second call, you will find some validation functions, which eventually lead to

// \Magento\Framework\Config\View

/**
 * Get excluded file list
 *
 * @return array
 */
public function getExcludedFiles()
{
    $items = $this->getItems();
    return isset($items['file']) ? $items['file'] : [];
}

/**
 * Get excluded directory list
 *
 * @return array
 */
public function getExcludedDir()
{
    $items = $this->getItems();
    return isset($items['directory']) ? $items['directory'] : [];
}

/**
 * Get a list of excludes
 *
 * @return array
 */
protected function getItems()
{
    $this->initData();
    return isset($this->data['exclude']) ? $this->data['exclude'] : [];
}

But, there are a few issues here.

First, the function \Magento\Framework\Config\View::getItems always seems to return an empty array.

Second, the function \Magento\Framework\View\Asset\Bundle\Manager::isExcludedFile will always return false

/**
 * Check if asset file is excluded
 *
 * @param string $filePath
 * @param LocalInterface $asset
 * @return bool
 */
protected function isExcludedFile($filePath, $asset)
{
    /** @var $asset LocalInterface */
    $filePathInfo = $this->splitPath($filePath);
    if ($filePathInfo && $this->compareModules($filePathInfo, $asset)) {
        return $asset->getSourceFile() == $filePathInfo['excludedPath'];
    }
    return false;
}

Because $asset->getSourceFile() is the absolute path to the asset file, while $filePathInfo['excludedPath'] is a relative path.

So, as far as I can see the the <exclude> configuration will not work anyway. But if it would work the asset would be excluded from the \Magento\Framework\View\Asset\Bundle.

1
  • Does this functionality now work in Magento 2.3+?
    – Mageician
    Jun 25, 2020 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.