Skip to content

Commit

Permalink
#292 Add support for automatic tailwind config merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wigman committed Jun 15, 2022
1 parent f753873 commit 6729aec
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Observer/RegisterModuleForHyvaConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Hyvä Themes - https://hyva.io
* Copyright © Hyvä Themes 2020-present. All rights reserved.
* This product is licensed per Magento install
* See https://hyva.io/license
*/

declare(strict_types=1);

namespace Hyva\ReactCheckout\Observer;

use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class RegisterModuleForHyvaConfig implements ObserverInterface
{
/**
* @var ComponentRegistrar
*/
private $componentRegistrar;

public function __construct(ComponentRegistrar $componentRegistrar)
{
$this->componentRegistrar = $componentRegistrar;
}

public function execute(Observer $event)
{
$config = $event->getData('config');
$extensions = $config->hasData('extensions') ? $config->getData('extensions') : [];

$moduleName = implode('_', array_slice(explode('\\', __CLASS__), 0, 2));

$path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);

// Only use the path relative to the Magento base dir
$extensions[] = ['src' => substr($path, strlen(BP) + 1)];

$config->setData('extensions', $extensions);
}
}
15 changes: 15 additions & 0 deletions src/etc/frontend/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!--
/**
* Hyvä Themes - https://hyva.io
* Copyright © Hyvä Themes 2020-present. All rights reserved.
* This product is licensed per Magento install
* See https://hyva.io/license
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="hyva_config_generate_before">
<observer name="hyva_react_checkout" instance="Hyva\ReactCheckout\Observer\RegisterModuleForHyvaConfig"/>
</event>
</config>
15 changes: 15 additions & 0 deletions src/view/frontend/tailwind/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Since Hyvä Themes 1.1.14 this file is automatically
* merged into your Hyvä Theme Tailwind config
*
* See https://docs.hyva.io/hyva-themes/compatibility-modules/tailwind-config-merging.html
*
**/

module.exports = {
purge: {
content: [
'../../../reactapp/src/**/*.jsx',
]
}
}

0 comments on commit 6729aec

Please sign in to comment.