clawrock / magento2-sass-preprocessor
Module for Sass processing during static content deployment
Installs: 12 089
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 4
Open Issues: 0
Type:magento2-module
Requires
- leafo/scssphp: ^0.7.7
- magento/framework: ~101.0|~102.0|~103.0
- magento/module-developer: ^100.2
- magento/module-store: ^100.2|^101.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpmd/phpmd: ^2.6
- phpunit/phpunit: ^6.5
- sebastian/phpcpd: ^3.0
- squizlabs/php_codesniffer: ^3.3
README
Magento 2 - Sass Preprocessor module
Module for Sass processing during static content deployment with additional Gulp workflow to improve Magento 2 development speed. It compiles SCSS using scssphp
and process standard @import
instruction as well as @magento_import
.
Installation
- Install module via composer
composer require clawrock/magento2-sass-preprocessor
- Register module
php bin/magento setup:upgrade
- Compile Sass theme using
php bin/magento setup:static-content:deploy -f
Example theme
Works with
Preprocessor
- Magento 2.2 - 2.3
- PHP 7.0 - 7.2
Gulp
- Node.js 10+
Gulp
- Install Node.js
- Install Gulp configuration
php bin/magento dev:gulp:install
- Install Gulp and required dependencies
npm install
- Define theme configuration
php bin/magento dev:gulp:theme
- Symlink theme to pub/static folder
gulp exec:[theme_key]
- Compile SCSS
gulp scss:[theme_key]
- Watch for changes
gulp watch:[theme_key]
It also supports LESS, instead of SCSS use less like gulp less:[theme_key]
Use additional flags to enable more watchers:
--phtml
: reload when phtml file is changed--js
: reload when js file is changed
Configure theme
You can manually configure theme like in Gruntfile which is shipped with Magento or use php bin/magento dev:gulp:theme
command which will configure it for you.
Reference: Grunt configuration file
Commands
List of gulp commands:
gulp clean:[theme_key]
gulp deploy:[theme_key]
gulp exec:[theme_key]
gulp scss:[theme_key]
gulp less:[theme_key]
gulp watch:[theme_key]
gulp build:scss:[theme_key]
gulp build:less:[theme_key]
gulp dev:scss:[theme_key]
gulp dev:less:[theme_key]
BrowserSync
Pass --proxy http://magento.test
argument to gulp watch:[theme_key]
or gulp dev:scss[theme_key]
where http://magento.test is Magento base url and BrowserSync will be enabled.
You can configure BrowserSync in dev/tools/gulp/config/browser-sync.json
.
Reference
Example usage
gulp dev:scss:my_theme --proxy http://m2.test --phtml
Troubleshooting
If you had previously installed Grunt, please make sure you have removed package-lock.json and node_modules folder. Then run npm install
.
For development with enabled SSL please provide path to SSL key and certificate in BrowserSync configuration file.