7

How can I add custom less file and in a particular theme compile less file in Magento 2 ?

2 Answers 2

12

Just add new file here

app\design\frontend\Vendor\Themename\web\css\source\_new.less

and import this file in source file given path below

app\design\frontend\Vendor\Themename\web\css\source\_sources.less

import your file

(if there is not available _source.less file in your theme then go to vendor\magento\theme-frontend-blank\web\css\source folder and copy file in your custom theme)

@import '_new.less';
  1. clear cache
  2. php bin/magento setup:static-content:deploy
3
  • Tried this and it is not working
    – Scott
    Feb 13, 2019 at 18:56
  • @Scott try this: app/design/frontend/Vendor/Tname/web/css/source/_extend.less May 10, 2019 at 6:42
  • thanks Yusuf. that's eventually what I figured out
    – Scott
    May 31, 2019 at 21:51
2

Above answer is not working I don't know how its accepted: If you want to add custom common css file, you have to follow below steps:

1) create file at following locationi in your custom theme

app\design\frontend\Vendor\Themename\web\css\source\_common.less

2) create _extend.less file at following location

app\design\frontend\Vendor\Themename\web\css\source\_extend.less

3) add following line at top of this file

@import '_common.less';

just clear cache & generate content if on production.

2
  • where should i put ' @import '_common.less'; at? thanksw Sep 29, 2020 at 21:10
  • in side _extend.less file. Which is actually file in your theme who is extending the magento's module css file. In which you want to add modifications. See topic how can I extend magento css file? Sep 30, 2020 at 11:47

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.