24/12
2017
Magento2 grunt sprite generation tool
Sprite Generation for Magento 2, based on Grunt, (*2)
composer require magekey/grunt-sprite
cd vendor/magekey/grunt-sprite
npm install
grunt setup
create a convenient symlink grunt-sprite
and config file grunt-sprite-config.json.sample
in the project root.grunt-sprite-config.json.sample
to grunt-sprite-config.json
and define your themesLESS Example:, (*3)
{ "path": { "sprite_mytheme": "<%= project %>/app/design/frontend/Vendor/mytheme/web" }, "sprite": { "mytheme": { "src": "<%= sprite_mytheme %>/images/sprite/*.png", "dest": "<%= sprite_mytheme %>/images/sprite.png", "destCss": "<%= sprite_mytheme %>/css/source/_sprite.less" } } }
SCSS Example:, (*4)
{ "path": { "sprite_mymodule": "<%= project %>/app/design/frontend/Vendor/mytheme" }, "sprite": { "test_module": { "src": "<%= sprite_mymodule %>/MyPackage_Module/web/images/sprite/*.png", "dest": "<%= sprite_mymodule %>/MyPackage_Module/web/images/sprite.png", "destCss": "<%= sprite_mymodule %>/MyPackage_Module/web/scss/_sprite.scss", "cssTemplate": "<%= src %>/templates/scss.template.handlebars" } } }
cd grunt-sprite grunt sprite:<sprite>
Add sprites to your theme in app/design/Vendor/theme/web/css/_styles.less, (*5)
@import 'source/lib/_lib.less'; // Global lib @import 'source/_sources.less'; // Theme styles @import 'source/_components.less'; // Components styles (modal/sliding panel) // Add new line to import sprites @import 'source/_sprite.less'; // Sprites