Created
February 23, 2017 10:16
-
-
Save szeidler/b9fd2feeb569c03de9dfb30f703e49d1 to your computer and use it in GitHub Desktop.
Gulp files for Drupal theming (including clever drush cache clearing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gulp file for Drupal theming, including clever drush cache clearing. | |
* | |
* Usage in docker4drupal environment: `gulp --docker` | |
* It ensures, that drush is executed from the php container. | |
*/ | |
var gulp = require('gulp'); | |
var argv = require('yargs').argv; | |
var plumber = require('gulp-plumber'); | |
var sass = require('gulp-sass'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var filter = require('gulp-filter'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var browserSync = require('browser-sync'); | |
var reload = browserSync.reload; | |
var shell = require('gulp-shell'); | |
var imagemin = require('gulp-imagemin'); | |
var svgmin = require('gulp-svgmin'); | |
var drush_path = 'drush'; | |
if (argv.docker) { | |
drush_path = 'docker-compose exec --user 82 php drush'; | |
} | |
// sass task | |
gulp.task('sass', function () { | |
return gulp.src('sass/**/*.scss') | |
.pipe(plumber()) | |
.pipe(sourcemaps.init()) | |
.pipe(sass.sync({ | |
precision: 10 | |
}).on('error', sass.logError)) | |
.pipe((autoprefixer({ | |
browsers: ['last 3 versions'] | |
}))) | |
.pipe(sourcemaps.write()) | |
.pipe(gulp.dest('css')) | |
}); | |
// process JS files and return the stream. | |
gulp.task('js', function () { | |
return gulp.src('js/source/*js') | |
.pipe(gulp.dest('js/build')); | |
}); | |
// minimize images | |
gulp.task('imagemin', function () { | |
return gulp.src('images/source/**.*') | |
.pipe(imagemin({ | |
progressive: true | |
})) | |
.pipe(gulp.dest('images/optimized')) | |
}); | |
// run drush to clear the theme registry. | |
gulp.task('drush', function () { | |
return shell.task([ | |
drush_path + ' cc theme-registry' | |
]); | |
}); | |
// BrowserSynk | |
gulp.task('browser-sync', function () { | |
//watch files | |
var files = [ | |
'css/*.css', | |
'js/**/*js', | |
'images/**/*', | |
'templates/*.php' | |
]; | |
}); | |
// Default task to be run with `gulp` | |
gulp.task('default', ['sass', 'js'], function () { | |
gulp.watch('sass/**/*.scss', ['sass']); | |
gulp.watch('js/**/*.js', ['js']); | |
gulp.watch('images/source/**', ['imagemin']); | |
gulp.watch('**/*.{php,inc,info}', ['drush']); | |
gulp.watch('**/*.info', ['drush']); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "###your_theme_name###", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"postinstall": "find node_modules/ -name \"*.info\" -type f -delete", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "MIT", | |
"devDependencies": { | |
"browser-sync": "^2.12.8", | |
"gulp": "^3.9", | |
"gulp-autoprefixer": "^3.1.0", | |
"gulp-filter": "^1.0.2", | |
"gulp-imagemin": "^3.0.2", | |
"gulp-plumber": "^1.1.0", | |
"gulp-sass": "^2.1.0", | |
"gulp-shell": "^0.5.1", | |
"gulp-sourcemaps": "^1.6.0", | |
"gulp-svgmin": "^1.2.3", | |
"yargs": "^6.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment