Adding new less imports in Magento 2 in Development mode
Oct 3, 2016 · 1 minute readCategory: magento2
Importing a new less file when extending a Magento theme needs a few steps:
- Create the new file in your theme (in the
app/design/frontend/<vendor>/<theme>/web/css/source/folder) - Add an import directive for that file in your normal
_extend.lessfile with//@magento_import '_newfile.less';(yes, with the//- see here) - For development mode, build the files using the
grunt execcommand†. This creates symlinks in yourpub/static/frontend/<vendor>/<theme>/<locale>/css/source/folder - For production mode, build the files using the
bin/magento setup:source-theme:deploycommand. This copies the less files into thepub/static/frontend/<vendor>/<theme>/<locale>/css/source/folder
That should be it.
†- I’m pretty sure the bin/magento dev:source-theme:deploy command should cover this, but for some reason it didn’t work for me