Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of overwriting the minify_exclude value, append your css file to it. #19

Merged
merged 3 commits into from
Feb 25, 2018
Merged
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
65 changes: 65 additions & 0 deletions Plugin/View/ExcludeCssFromMinification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*/

namespace Magenerds\PageDesigner\Plugin\View;

use Magento\Framework\View\Asset\Minification;

/**
* Class ExcludeCssFromMinification
*
* @package Magenerds\PageDesigner\Plugin\View
* @file ExcludeCssFromMinification.php
*/
class ExcludeCssFromMinification
{
/**
* Adds css file to the minify_exclude config setting to avoid a bug with minification of this css file
* Only occurs with tubalmartin/cssmin < v2.4.8-p7
*
* Ref:
* - https://github.com/magento/magento2/issues/8552
* - https://github.com/magento/magento2/pull/9027
* - https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/commit/59e5e8b0b8225244aea90da3cd5f81b1ba575da2#diff-80f11f7052c350cef68c3041a5479789R588
*
* @param Minification $subject
* @param callable $proceed
* @param string $contentType
* @return string[]
*/
public function aroundGetExcludes(Minification $subject, callable $proceed, $contentType)
{
$result = $proceed($contentType);

if ($contentType !== 'css' || !$this->isCssminLibraryOlderThanVersion3()) {
return $result;
}

$result[] = '/Magenerds_PageDesigner/css/pd-ui.css';

return $result;
}

/**
* Checks if the current version of tubalmartin/cssmin can cause problems with minifying
* Strictly speaking, not all versions 2.x.x of the library caused issues (since it got fixed in v2.4.8-p7),
* but here we check to see if version 2 is being used, where the class was called 'CSSmin' and existed in the global namespace,
* from version 3 on out, the class name was changed and put in a namespace: 'tubalmartin\CssMin\Minifier'
* So if we detect version 2 of the library, we assume it is broken
*
* Ref:
* - https://github.com/tubalmartin/YUI-CSS-compressor-PHP-port/compare/v2.4.8-p10...v3.0.0#diff-411bfa1ca68f3e86ffb0276bcffd838dL22
*
* @return bool
*/
private function isCssminLibraryOlderThanVersion3()
{
return class_exists(\CSSmin::class);
}
}
8 changes: 0 additions & 8 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<dev>
<!-- temporary solution until https://github.com/magento/magento2/issues/8552 is fixed-->
<css>
<minify_exclude>
/Magenerds_PageDesigner/css/pd-ui.css
</minify_exclude>
</css>
</dev>
<pagedesigner>
<general>
<css_classes_column>pd-highlight</css_classes_column>
Expand Down
6 changes: 6 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
<plugin name="Magenerds_PageDesigner::widgetDecodeBackend"
type="Magenerds\PageDesigner\Plugin\Block\WidgetOptionsPlugin"/>
</type>

<!-- needed for tubalmartin/cssmin < v2.4.8-p7 -->
<type name="Magento\Framework\View\Asset\Minification">
<plugin name="Magenerds_PageDesigner::excludeCssFromMinification"
type="Magenerds\PageDesigner\Plugin\View\ExcludeCssFromMinification"/>
</type>
</config>