2
  1. Create theme app/design/frontend/Vendorname/default
  2. Try add my.less file for impot, or add code with new class and style to _extends.less to app/design/frontend/Vendorname/default/web/css/sourse.
  3. rm -rf pub/static/*
  4. rm -rf var/view_preprocessed/*
  5. php /var/www/html/bin/magento cache:clean
  6. php /var/www/html/bin/magento setup:static-content:deploy
  7. php /var/www/html/bin/magento cache:clean

But this not work. I read a lot, but I do not see a particular decision. Please write how to correctly add less file to Magento 2? Please help.

0

1 Answer 1

3

We can import by using @import or @magento_import directive

1) The @import directive rules of usage

@import 'your_custom.less';

2) The @magento_import directive - must be commented out with two slashes

//@magento_import 'your_custom.less';

For example: your_custom.less is under app/design/frontend/Vendor/Theme/web/css/source/

-app/design/frontend/Vendor/Theme/web/css/source/_extend.less

@import 'your_custom.less';

You can read more here: http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/css-topics/css-preprocess.html

8
  • I add 2 files _theme.less and _my_file.less to app/design/frontend/Vendorname/default/web/css/sourse. In _theme.less write @import 'source/_my_file.less'; Remove pub/static. Site not work, now not work all style.
    – Sylon
    Dec 27, 2016 at 6:26
  • You should add our custom file at the end of the file. Keep the old import files. Dec 27, 2016 at 6:29
  • I save all code _theme.less and add at the end @import 'source/_my_file.less'; Maybe _theme.less not good for import.
    – Sylon
    Dec 27, 2016 at 6:31
  • Did you run static deploy command again? Dec 27, 2016 at 6:32
  • Yep. When I return original _theme.less and static deploy command again, site work. With @import 'source/_my_file.less'; - not work.
    – Sylon
    Dec 27, 2016 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.