Skip to content

Instantly share code, notes, and snippets.

@joelpittet
Last active May 16, 2017 23:37
Show Gist options
  • Save joelpittet/11405038 to your computer and use it in GitHub Desktop.
Save joelpittet/11405038 to your computer and use it in GitHub Desktop.
Drupal Theme Gulp'd
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var compass = require('gulp-compass');
var imagemin = require('gulp-imagemin');
var pngcrush = require('imagemin-pngcrush');
var livereload = require('gulp-livereload');
var shell = require('gulp-shell')
// Lint Task
gulp.task('lint', function() {
return gulp.src('js/src/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Compress images
gulp.task('images', function () {
return gulp.src('img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngcrush()]
}))
.pipe(gulp.dest('img'));
});
// Compile Our Sass with Bundle[d] Compass
gulp.task('sass', function() {
return gulp.src('./sass/*.scss')
.pipe(compass({
config_file: './config.rb',
bundle_exec: true
}))
.pipe(gulp.dest('css'));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('js/src/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('js'))
.pipe(rename('main.min.js'))
.pipe(uglify())
.pipe(gulp.dest('js'));
});
// Run drush to clear the theme registry.
gulp.task('drush', shell.task([
'drush cache-clear theme-registry'
]));
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('js/**/*.js', ['lint', 'scripts']);
gulp.watch('sass/**/*.scss', ['sass']);
// Watch php, inc and info file changes to run drush task.
gulp.watch('**/*.{php,inc,info}', ['drush']);
// Start livereload and watch on css/js changes.
var server = livereload();
gulp.watch('js/*.js,css/*.css').on('change', function(file) {
server.changed(file.path);
});
});
// Default Task
gulp.task('default', ['lint', 'sass', 'images', 'scripts', 'watch']);
@intergalactic-overlords

Hi, I've been playing around with gulp in drupal themes as well and drupal seems to have a problem with the lcov.info file in [mytheme]/node_models/gulp-watch/coverage/

Can I ask you how you solved this issue? thx

@tim-smart
Copy link

@intergalactic-overlords

I solved this by adding to my package.json:

  "scripts": {
    "prepublish": "find node_modules -name '*.info' -exec rm -f {} \\;"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment