version v2.13 Maintained by Salsa Digital.
Grunt for Drupal is a grunt project with commonly used tasks to assists Drupal theme and module development.
If not you can get it from here.
If not you can get it by running sudo npm install -g grunt-cli
in command line.
- User COMPOSER to install PHP_CodeSniffer
composer global require "squizlabs/php_codesniffer=2.5.1"
- Versions above 2.6.0 have an issue when running within grunt
- Find PHP_CodeSniffer home
- By default:
~/.composer/vendor/bin/phpcs
- Use PHP_CodeSniffer location in bin option in:
.local_grunt_settings.json
(See below - 'How do I use my personal preferences with grunt?').
- By default:
- Install Drupal Standard
- Go to here and download coder 8.x-2.*
- Extract and add
coder_sniffer/Drupal
folder to your CodeSniffer Standards folder. E.g.~/.composer/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/Drupal
- Navigate to your Drupal theme root folder.
- Clone the repo:
git clone https://github.com/salsadigitalauorg/grunt_for_drupal.git ./grunt
. - Create your
./src
directory (Seeexample folder setup script
below for folder structure). - Add your source files (SCSS, JS, Images) in
./src
sub-directories. - Create a
./grunt/project_grunt_settings.json
file and configure project settings.
- If you need personalised settings, create a
./grunt/.local_grunt_settings.json
file (see below). - Use command line to navigate inside the
./grunt
directory and typenpm install
to install necessary modules. - Type
grunt
for a full compile (everything). - Type
grunt watch
for an automatic compile on file change (only necessary commands will run).
Within the Gruntfile.js
, the following processes are run:
- jsbeautifier
- Formats working JS and SCSS files.
- concat
- Merges all JS files into 1. Allows breaking up of JS files into components.
- sass
- Compile the SCSS.
- auto prefixing
- Automatically adds -webkit- -moz- -ms- prefixes to CSS styles.
- pngmin, svgmin, imagemin
- Optimize images.
- phpcs
- Code Sniffer for Drupal PHP files.
Within the '/src' folder, place all working SCSS, JS and image files in their respective subdirectories. When run, Grunt will populate the '/dist/css', '/dist/js' and 'dist/images' folders.
An example of a src folder setup is:
src/
sass/
`styles.scss`
js/
`scripts.js`
images/
jpg/
optimise/
`optimise.jpg`
raw/
`raw.jpg`
png/
optimise/
`optimise.png`
raw/
`raw.png`
svg/
optimise/
`optimise.svg`
raw/
`raw.svg`
An example folder setup script (for bash) to run from within the theme/grunt folder:
mkdir ../dist
mkdir ../src
mkdir ../src/sass
mkdir ../src/js
mkdir ../src/images
mkdir ../src/images/jpg
mkdir ../src/images/jpg/optimise
mkdir ../src/images/jpg/raw
mkdir ../src/images/png
mkdir ../src/images/png/optimise
mkdir ../src/images/png/raw
mkdir ../src/images/svg
mkdir ../src/images/svg/optimise
mkdir ../src/images/svg/raw
Grunt for Drupal is set to run with defaults, but each project will likely
have it's own unique settings. You can use .local_grunt_settings.json
and project_grunt_settings.json
to add these custom settings per-project.
Create a JSON file called .local_grunt_settings.json
or project_grunt_settings.json
in the same directory as Gruntfile.js. When grunt runs it will use the settings
from this file instead of the defaults.
This file is used for defining settings specific to the environment it's being used on (your local computer). This shouldn't be a part of the repo as it relates only to you, so make sure git is set to ignore this file.
{
"phpcs_bin": "/Users/salsadigital/pear/bin/phpcs"
}
This file relates to the project and should contain project-wide settings. This should be included in the repository.
{
"custom_modules_directory": "../../modules/custom/",
"profile_modules_directory": "../../modules/custom/",
"custom_script_paths": "custom/path/**/*.js",
"custom_beautify": [],
"theme_directory": "../",
"use_compass": false,
"use_image_compression": false,
"use_prefixer": true,
"use_scss_filename": ["styles"],
"prefixer_browsers": ["last 2 versions", "not ie <= 8", "iOS >= 7"],
"drupal_version": 8
}
custom_modules_directory
- This is the directory to your custom modules. If not defined then no custom module files will be validated.
profile_modules_directory
- This is the directory to your profile modules. If not defined then no profile module files will be validated. Works the same as custom_modules_directory.
custom_script_paths
- Array of any additional scripts to add that may not be in /src folder.
These will be beautified and concatenated with any
src/js
scripts.
- Array of any additional scripts to add that may not be in /src folder.
These will be beautified and concatenated with any
custom_beautify
- Array of additional files to run through the beautifier. This can be used to include / exclude particular files.
theme_directory
- This is the directory to your theme. If not defined, theme directory will default to one folder level above this.
phpcs_bin
- This is your local system's directory to PHP Code Sniffer. If not defined, then PHPCS will not run. Note: This only works in Local Setting.
use_compass
- If set to
true
will use compass config.rb to compile stylesheets. If not defined, will default to LibSass.
- If set to
use_image_compression
- If set to
true
will use compress SVG / PNG / JPG images in src/images folder.
- If set to
drupal_version
- Set an integer (e.g.
7
or8
).
- Set an integer (e.g.
use_prefixer
- Use the Auto Prefixer. Set to
true
by default.
- Use the Auto Prefixer. Set to
use_scss_filename
- Set a string / array to the SCSS filename to target in the theme (e.g.
styles
). This will also affect the .css filename (e.g. "styles.scss" -> "styles.css").
- Set a string / array to the SCSS filename to target in the theme (e.g.
prefixer_browsers
- Define what browsers Auto Prefixer should support.
Default is
last 2 versions
,not ie <= 8
.
- Define what browsers Auto Prefixer should support.
Default is
- If the task is not running correctly, try
grunt --verbose
and search the output for issues.