Simple Gulpfile for Magento2

Overview

Magento 2 gulpfile

Gulp tasks and configuration necessary to setup gulp-based front-end workflow for deploying and watching theme customizations.

Requirements

  • Node.js
  • gulp-cli (intalled globally) - npm install -g gulp-cli
  • Magento 2 project with LESS based theme

If you need SASS support I highly recommend the excellent Frontools by Snowdog

Installation

  1. Download gulpfile.js into the root folder of your project

  2. Add the following dependancies to your local package.json file (into devDependancies):

     "autoprefixer": "^9.4.10",
     "browser-sync": "^2.26.7",
     "chalk": "^2.1.0",
     "cssnano": "^4.1.10",
     "fancy-log": "^1.3.3",
     "gulp": "^4.0.2",
     "gulp-clean": "^0.3.2",
     "gulp-eslint": "^5.0.0",
     "gulp-image": "^6.0.0",
     "gulp-image-resize": "^0.13.1",
     "gulp-less": "^4.0.1",
     "gulp-postcss": "^8.0.0",
     "gulp-rename": "^2.0.0",
     "gulp-run": "^1.7.1",
     "gulp-sourcemaps": "^2.6.0",
     "gulp-stylelint": "^8.0.0",
     "minimist": "^1.2.5",
     "postcss-less": "^3.1.2",
     "postcss-uncss": "^0.17.0",
     "stylelint": "^9.10.0",
     "stylelint-config-standard": "^18.2.0",
     "uncss": "^0.17.3"
    
  3. Run

     yarn install
    

    or

     npm install
    

Configuration

Copy dev/tools/gulp/configs/ into your root directory and update configuration using the following templates:

themes.js

	module.exports = {
		<"theme-alias">: {
			"locale": locale,
			"lang": "less",
			"area": "frontend",
			"vendor": <"Vendor">,
			"name": <"Theme-name">,
			"files": [
				"css/styles-m",
				"css/styles-l",
				"css/<custom-css>"
			]
		}
	};
  • locale: local language,
  • lang: css preprocessor (currently only less is supported)
  • area: area, one of (frontend|adminhtml|base),
  • vendor: developing company,
  • name: theme name,
  • files: Files to compile

browser-sync.js

    module.exports = {
      	proxy : "local.magento"
    }

proxy: Local address of your site

stylelint.js

	module.exports = {
		"extends": "stylelint-config-standard",
		"ignoreFiles": ["/**/_module.less", "/**/_widgets.less"],
		"rules": {
			"at-rule-empty-line-before": null,
			"no-descending-specificity": true,
			"indentation": 4,
			"string-quotes": "single",
			"selector-max-id": 0,
			"max-nesting-depth": 4,
			"number-leading-zero": "never",
			"max-empty-lines": 2,
			"font-family-no-missing-generic-family-keyword": null
		}
	}

Update rules with your custom ones adding to or overriding the existing standard rules.

eslint.js

module.exports = {
	"configFile": "./dev/tools/gulp/configs/.eslintrc"
}

Note: ESlint configuration is specified within .eslintrc file. Please change your eslint environments and rules there.

uncss.js

module.exports = {
	baseUrl: 'http://local.magento',
	entrypoints: [
		{
			page: 'hp',
			path: '/',
		},
		{
			page: 'pdp',
			path: '/juno-jacket.html',
		},
		{
			page: 'plp',
			path: '/women/tops-women/jackets-women.html',
		}
	]
}
  • baseUrl: Local url of your site
  • page: page identifier (will used in css file name eg. styles-m-hp.css)
  • path: path to page on storefront relative to base url

Usage

To see all available commands in the console run gulp --tasks

Basic tasks

Lint less files:

gulp less:lint [--theme-alias]

Note: _module.less and _widget.less are excluded from linting

Compile less to CSS:

gulp less:compile [--theme-alias]

Alias for less:lint and less:compile sequence:

gulp less [--theme-alias]

Lint js files:

gulp js:lint [--theme-alias]

Alias for js:lint:

gulp js [--theme-alias]

UnCSS main css files:

gulp css:uncss [--theme-alias]

Note: this task requires uncss configuration file (dev/tools/gulp/configs/uncss.js)

Minify css files using postCss:

gulp css:minify [--theme-alias]

Optimize images in the {theme}/web/images folder:

gulp image:theme:optimize [--theme-alias]

Note: this task overwrites existing image files. If you want to keep the original files specify optimized images destination folder in gulp.dest pipe

Optimize specific images in the pub/media folder:

gulp image:media:optimize [--theme-alias --input --output]

Resize specific images:

gulp image:resize [--theme-alias --input --output --width --height --crop --upscale --gravity --format --quality --background --percentage --cover]

Clean local cache in var/page_cache/ var/cache/ /var/di/ /var/generation/:

gulp clean:cache [--theme-alias]

Clean static assets in pub/static and var/view_preprocessed folders:

gulp clean:static [--theme-alias]

Create aliases in pub/static folder:

gulp source [--theme-alias]

Manually trigger static asset deployment for frontend:

gulp deploy:static [--theme-alias]

Manually trigger static asset deployment for admin:

gulp deploy:admin [--theme-alias]

Serves static assets and watches for less file changes in vendor modules/themes:

gulp serve [--theme-alias]

Task sequences Lint and compile less:

gulp less [--theme-alias]

JS processing:

gulp js [--theme-alias]

Rebuild aliases and compile less (eg. when adding new less files):

gulp refresh [--theme-alias]

Dev build - clean static assets, lint, compile and watch less files for changes:

gulp dev [--theme-alias]

Prod build - clean static assets, lint, compile and optimize CSS (uncss and minify):

gulp build [--theme-alias]

Note: [--theme-alias] is optional, the first available theme in themes.js is used by default

License

This project is licensed under GNU General Public License v3.0

You might also like...
Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in.

Metrics Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics API that doesn't cau

Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers

Magento 2 SMTP Extension - Gmail, G Suite, Amazon SES, Office 365, Mailgun, SendGrid, Mandrill and other SMTP servers. For Magento 2.0.x, 2.1.x, 2.2.x

Simple PHP Pages - A simple puristic PHP Website Boilerplate
Simple PHP Pages - A simple puristic PHP Website Boilerplate

Simple PHP Pages - A simple puristic PHP Website Boilerplate 🚀 Hey! This project provides simple and basic concepts for PHP pages. It includes ideas

Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less.

Sslurp v1.0 by Evan Coury Introduction Dealing with SSL properly in PHP is a pain in the ass and completely insecure by default. Sslurp aims to make i

Currency is a simple PHP library for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangerate.host

Currency Currency is a simple PHP library for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangera

Simple IT Documentation Solution for MSPs

SimpleMSPDoc RC 1.0 I wasn't happy with what other IT documention software had. I felt they over complicated things and required so much clicky clicky

Simple customizable captcha script for bot prevention in php language.

phpCaptcha Simple customizable captcha script for bot prevention in php language. Usage ?php session_start(); $status = ""; if ($_SESSION['captcha']

Simple WHOIS script with beautiful design.
Simple WHOIS script with beautiful design.

Simple PHP Whois It is ideal in terms of design and has easy operation. / Tasarım açısından idealdir ve kullanımı kolaydır. It has a simple interface.

A simple API with Guzzle wrapper, providing easy access to wppconnect's endpoints.

WPPConnect Team Wppconnect Laravel Client A simple API with Guzzle wrapper, providing easy access to wppconnect's endpoints. Requirements PHP 7.4 or n

Releases(3.4.0)
Owner
Rocket Web FED
Rocket Web Front-end Development
Rocket Web FED
Magento2 Turkish Translation / Magento2 Türkçe Çevirisi

Magento 2 Türkçe Dil Paketi Magento2 için Türkçe Dil Paketi Magento2 içinde standart olarak gelen tüm tercüme dosyaları derlenmiş ve bu paket oluşturu

Hidayet Ok 28 Dec 13, 2022
A simple script to convert extensions from Magento1 to Magento2

ConvertM1M2 Background The purpose of this script is to automate as much as possible the initial conversion of a Magento 1 extension, and allow develo

Boris Gurvich 144 Dec 14, 2022
Docker-magento2 - 🐳 Docker containers with all required Magento 2 dependencies installed available as FPM through Nginx and CLI

Magento 2 Docker A collection of Docker images for running Magento 2 through nginx and on the command line. Quick Start cp composer.env.sample compose

Meanbee 454 Dec 27, 2022
Magento2 + Varnish + PHP7 + Redis + SSL (cluster ready)

Docker Magento2: Varnish + PHP7 + Redis + SSL cluster ready docker-compose infrastructure Infrastructure overview Container 1: MariaDB Container 2: Re

Fabrizio Balliano 332 Dec 30, 2022
Guest to Customer for Magento2 - Quickly and easily convert existing guest checkout customers to registered customers.

Guest to Customer for Magento 2.0 For Magento 2.0.x, 2.1.x, 2.2.x, 2.3.x and 2.4.x In general E-commerce, shoppers do not like to create an account du

MagePal :: Magento Extensions 66 Oct 7, 2022
Magento2 British Language Pack (en_GB)

Links Website: https://github.com/cubewebsites/magento2-language-en-gb What's Up With The Fork? This fork is created from the original for 3 main reas

Ashraf Vali 3 Apr 28, 2021
Magento2 Spanish (Argentina) language pack build from Crowdin community translation tool.

Magento2-language-es_ar Magento2 Spanish (Argentina) language pack build from Crowdin community translation tool. Paquete de idioma de Español (Argent

SemExpert 2 Apr 7, 2021
Magento2 Deployment with Deployer (Skeleton)

MageDeploy2 Base Magento2 Deployment Setup using Robo and Deployer. This is the base project you should base your deployments on. It provides an confi

Matthias Walter 44 Jul 18, 2022
Developer Toolbar for Magento2

Developer Toolbar for Magento2 About Hope this debug toolbar can speed up Magento2 development module. Any feedback and idea to improve this toolbar w

Vincent Pietri 423 Dec 28, 2022
Magento2 Plugin for Conversion Pixel/API of Tiktok

Tiktok Conversion Pixel Analytics Plugin Magento2 Table of Contents About Getting Started About Tiktok Pixel is the Plugin used to track events, which

Rishi Gupta 3 Jun 27, 2022