Explanation
I'm really not a fan of loading all the CSS on every page regardless of whether it's required, to me this is bad practice. Therefore I am creating CSS files for certain areas, e.g homepage.css, account.css, product-page.css.
My problem is I now need to import Magento 2's variables and mixins, especially the media queries and media-common
variables.
My Code
I have tried adding the below code to my LESS file but it returns an error, I have also tried reverse paths (../) but this didn't work and apparently is forbidden for security reasons (read in the Magento2 repo).
This is app/design/frontend/PartyShowroom/default/Magento_Cms/web/css/homepage.less
.
// As this file is not imported we need to import the variables/mixins etc.
@import 'source/lib/_responsive.less';
@media-target: 'mobile'; // Sets target device for this file
@media-common: true; // Sets not to output common styles
@import 'source/_theme.less';
// My custom less being imported
@import 'layout/homepage/_homepage-carousel.less';
@import 'layout/homepage/_homepage-themes.less';
This still returns the error:
NameError: variable @media-common is undefined
in _homepage-carousel.less on line 4, column 9:
// _____________________________________________
& when (@media-common = true) {
Yet the same code works in vendor/magento/theme-frontend-blank/web/css/styles-l.less
despite the lib not being in the same directory.
Question
How can I import the mixins/variables from lib into my own custom CSS file?
<css src="Magento_Checkout::css/checkout.css" />
tocheckout_index_index.xml
checkout.css
to a less file in the same location in the theme? and if so, how do you use grunt to compile that? After reading the question i was racking my head to how that would work, and couldn't find any info on setting that up.Magento_Checkout::css/checkout.css
to your theme indev/tools/grunt/configs/themes.js
. If that doesn't work try moving the file to the theme module and then leave outMagento_Checkout::