Alright, I've figured it out. _extend.less files are not picked up in adminhtml themes. I wish this was made clear in the documentation, but alas.
I've come up with the following workaround which allows for
_extend.less files to be used for applying styles to modules in the admin interface without creating any "hidden dependencies" on Magento's adminhtml theme CSS roots (as would be the case with copy/pasting files into your adminhtml theme).
There is a caveat I should mention for the "add another root CSS source file" method that I've described in this answer. Using this approach, redeclaring variables will not have any effect because of the manner in which LESS files are processed i.e., the root file is processed, LESS files are gathered, and CSS is generated. If you wish to be able to redeclare variables (e.g.,
@primary__color) you must copy/paste
styles.less from the Magento adminhtml theme into your own theme, then append the contents of my
extends.less file onto the end of the copy/pasted file. This unfortunately creates what I call a "hidden dependency" on the original file (which is subject to changes in future versions of
theme-adminhtml-backend) so it will become your responsibility to check for changes to this file whenever
theme-adminhtml-backend is updated, and copy those changes to your local copy.
Firstly, we must add another Root CSS Source File. This is described in the Magento 2 documentation as-so:
The .less files from which the .css files included in layout are
compiled. For example, in one of the layout files of the Magento Blank
theme, the following .css files are included in the head:
<css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
<css src="css/print.css" media="print"/>
For development mode, using Grunt as a LESS processor, add another Source to the theme declaration in
local-themes.js depending on how you have your environment setup. Your theme declaration should look something like this:
'css/extends' // we've added this file
This step is not necessary for server-side compilation mode, as Magento simply looks for corresponding LESS files depending on what CSS files are included in the page head.
That said, this new file (
extends.css) must be included in the layout in the same fashion as the other CSS source files for the theme. Since the
Magento_Backend module is responsible for this, lets add the layout update to that module in our own adminhtml theme.
Create the file:
Now we must create this Root CSS Source File.
Create the file:
With the contents:
// import theme-wide extend file (use this for importing other theme-level extension files)
// import module-specific extension file e.g. <ModuleDir>/web/css/source/_extend.less
Now you can apply changes to Magento modules in the admin interface in the same fashion as you can with a frontend theme by adding an
_extend.less file to the module's
web/css/source directory. You can also use the
<theme-root>/web/css/source/_extend.less to import other theme-wide LESS files as is recommended for frontend themes (e.g.,
I hope this helps someone.