0

I have custom theme in ..../design/frontend/MyVendor/my-theme folder. My main less file is in design/frontend/MyVendor/my-theme/web/css/my-main.less. Content of the main less file:

@import './source/_module.less';

Location of _module.less file is in the folder

design/frontend/MyVendor/my-theme/web/css/source/_module.less

Contents of _module.less:

@import 'module/_cart.less';
@import 'module/_minicart.less';
@import 'module/_checkout.less';

The way I include my main less file is in default_head_blocks.xml:

<head>
    <link rel="stylesheet/less" type="text/css" src="css/my-main.less" />
    ......

The file is included, no errors anywhere, run the fallowing commands:

magento cache:flush
rm -rf pub/static
rm -rf var/cache
rm -rf var/page_cache
rm -rf var/view_processed
bin/magento setup:static-content:deploy -f

both

magento cache:flush & bin/magento setup:static-content:deploy -f

run without ANY errors. Still, the changes I made in module/_minicart.less are no presented when I refresh the page. What is the problem?

3 Answers 3

0

The way I include my main less file is in default_head_blocks.xml:

<head>
        <css src="Vendor_Module::css/my-main.less"/>
</head>
0

The correct way I include a less file in default_head_blocks.xml is:

<head>
        <css src="Vendor_Module::css/my-main.css"/>
</head>

Where css/my-main.css is actually css/my-main.less. It automatically transforms it somehow. So basicaly you use file-name.css in default_head_blocks.xml but you write your code in file-name.less file

0

Rename your main less file to _extend.less from my-main.less.

Put it in below location

design/frontend/MyVendor/my-theme/web/css/source/_extend.less

Insert your other less file in _extend.less, Like this

@import 'module/_cart.less';
@import 'module/_minicart.less';
@import 'module/_checkout.less';

FYI module directory should be design/frontend/MyVendor/my-theme/web/css/source/module

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.