Question

So I am investigating Ben Mark's claim that is really easy to switch out the PHP Less pre-processor for a Sass one. https://twitter.com/benmarks/status/590219053437833217 (I don't buy it)

I have implmented a Sass Preprocessor and added in it via di.xml as below:

<type name="Magento\Framework\View\Asset\PreProcessor\AlternativeSource">
    <arguments>
        <argument name="alternatives" xsi:type="array">
            <item name="scss" xsi:type="array">
                <item name="class" xsi:type="string">TheExtensionLab\SassPreProcessor\PreProcessor\Adapter\Sass\Processor</item>
            </item>
        </argument>
    </arguments>
</type>

Which now processes my .sass files into .css files (mabey not use best PHP libary yet but no worries can change that later).

However I no longer want the .less files to be preprocessed. Is it possible to remove an argument via di.xml that has allready been added to a type? In this case less is allready added to AlternativeSource in Magento/Developer/etc/di.xml. I tried adding a empty node with the same item name but that didn't do the trick for me.

I could ofcourse just create a completely empty base theme that doesn't have any .less files in but that sucks because then I would also have no template files/layouts and would have to create those and keep them up to date.

Current progress : https://github.com/TheExtensionLab/Magento2Sass

If we can do this then that also brings up the issue of admin styles that are currently also .less but cross that bridge when we come it it.

Or if there is an alterative way to do this not have the overhead of the .less files but also have my theme and templates from the blank theme I am all ears.

Was it helpful?

Solution

You can't remove argument declared within other di.xml file.

But, it seems like the version of the code from your example is a little bit old.

In the current version (2.0.0), you can control over sort ordering of alternatives:

<virtualType name="AlternativeSourceProcessors">
    <arguments>
        <argument name="alternatives" xsi:type="array">
            <item name="scss" xsi:type="array">
                <item name="class" xsi:type="string">TheExtensionLab\SassPreProcessor\PreProcessor\Adapter\Sass\Processor</item>
            </item>
            <item name="less" xsi:type="array">
                <item name="after" xsi:type="string">scss</item>
            </item>
        </argument>
    </arguments>
</virtualType>

If your scss source file will be processed successfully, then compilation from less source won't be triggered at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top