In your custom module, you'll want to add an interceptor to \Magento\Framework\View\Asset\Minification::getExcludes
, which determines the files to exclude from minification.
Your files would look something like this:
MODULE/etc/di.xml (Be careful! Don't put it in etc/frontend/di.xml, it has to be etc/di.xml)
<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Asset\Minification">
<plugin name="my-exclude" type="Vendor\Module\Plugin\ExcludeFilesFromMinification" />
</type>
</config>
MODULE/Plugin/ExcludeFilesFromMinification.php
Magento < 2.2
<?php
namespace Vendor\Module\Plugin;
use Magento\Framework\View\Asset\Minification;
class ExcludeFilesFromMinification
{
public function aroundGetExcludes(Minification $subject, callable $proceed, $contentType)
{
$result = $proceed($contentType);
if ($contentType != 'js') {
return $result;
}
$result[] = 'Vendor_Module/js/your-js-filename';
return $result;
}
}
Magento > 2.2
<?php
namespace Vendor\Module\Plugin;
use Magento\Framework\View\Asset\Minification;
class ExcludeFilesFromMinification
{
public function afterGetExcludes(Minification $subject, array $result, $contentType)
{
if ($contentType == 'js') {
$result[] = 'Vendor_Module/js/your-js-filename';
}
return $result;
}
}