This tutorial will explain how to compile .less files to install, configure, and use Grunt in Magento 2. The main purpose of Grunt is to simplify repetitive tasks by automating compilation, minification, etc.
In Magento 2, If you want any single change in your theme you need to compulsory deploy again and again if you using the grunt you can easily compile the less and get the output.
For, Linux / Ubuntu user you can execute the below commands to install Node.js and check the version:
sudo apt-get update sudo apt-get install nodejs nodejs -v
To install it, Go to the root directory of Magento 2 and Run this below command in your terminal :
npm install -g grunt-cli
{"themes": "dev/tools/grunt/configs/local-themes"}
To
{"themes": "dev/tools/grunt/configs/themes"} You also like to read this : Add custom product image in magento 2
Add custom product image in magento 2
<Magento_Root_Directory>/dev/tools/grunt/configs/themes.js file and add this below code :
module.exports = { ... <theme_name>: { area: 'frontend', name: '<vendor_name>/<theme_name>', locale: '<language>', files: [ '<path_to_file1>', '<path_to_file2>' ], dsl: 'less' ... },
After running “grunt watch” will watch the *.less files and if some are changed, it will immediately rebuild the CSS file.
I hope this helps you. For any doubts regarding this topic, please write your doubts in the comments section.
In Magento
Apr 02, 2023
Do not miss a chance to grab exciting offers on Magento Development at Dolphin Web Solution. We are providing discounts on various Magento services this season. Go and grab yours today at our Magento Store.