Last active
November 8, 2016 17:25
-
-
Save sarahmonster/0805fe98c73aa5d46320d747658368a5 to your computer and use it in GitHub Desktop.
Gulp setup for WordPress themes
This file contains 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
*.map | |
node_modules/* |
This file contains 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
// Include Gulp | |
var gulp = require( 'gulp' ); | |
// Include Plugins | |
var sass = require( 'gulp-sass' ); | |
var autoprefixer = require( 'gulp-autoprefixer' ); | |
var imagemin = require( 'gulp-imagemin' ); | |
var pngquant = require( 'imagemin-pngquant' ); | |
var jshint = require( 'gulp-jshint' ); | |
var concat = require( 'gulp-concat' ); | |
var notify = require( 'gulp-notify' ); | |
var cache = require( 'gulp-cache' ); | |
var sourcemaps = require( 'gulp-sourcemaps' ); | |
var csscomb = require( 'gulp-csscomb' ); | |
var livereload = require( 'gulp-livereload' ); | |
var svgmin = require( 'gulp-svgmin' ); | |
var cheerio = require( 'gulp-cheerio' ); | |
var svgstore = require( 'gulp-svgstore' ); | |
// Styles tasks | |
gulp.task( 'styles', function() { | |
return gulp.src( 'assets/stylesheets/style.scss' ) | |
.pipe( sourcemaps.init() ) | |
.pipe( sass( { style: 'expanded' } ) ) | |
.on( 'error', notify.onError( function( err ) { | |
return "Stylesheet Error in " + err.message; | |
} ) ) | |
.pipe( autoprefixer( { browsers: ['last 2 versions', 'ie >= 9'], cascade: false } ) ) | |
//.pipe( csscomb() ) | |
.pipe( sourcemaps.write( './', { includeContent: false, sourceRoot: 'source' } ) ) | |
.on( 'error', function ( err ) { | |
console.error( 'Error!', err.message ); | |
} ) | |
.pipe( gulp.dest( './' ) ) | |
.pipe( livereload() ); | |
}); | |
// Scripts | |
gulp.task( 'scripts', function() { | |
return gulp.src( 'assets/js/*.js' ) | |
.pipe( jshint.reporter( 'default' ) ) | |
//.pipe( concat( 'main.js' ) ) | |
.pipe( gulp.dest( 'assets/js' ) ); | |
//.pipe( notify( { message: 'Scripts task complete' } ) ); | |
}); | |
// Minify our icons and make them into an inline sprite | |
gulp.task( 'icons', function() { | |
return gulp.src( 'assets/svg/icons/*.svg' ) | |
.pipe( svgmin() ) | |
.pipe( svgstore( { | |
fileName: 'icons.svg', | |
inlineSvg: true | |
} ) ) | |
.pipe( cheerio( { | |
run: function( $, file ) { | |
$( 'svg' ).addClass( 'hide' ); | |
$( '[fill]' ).removeAttr( 'fill' ); | |
}, | |
parserOptions: { xmlMode: true } | |
})) | |
.pipe( gulp.dest( 'assets/svg' ) ); | |
}); | |
// Generate style guide assets. | |
gulp.task( 'style-guide', function() { | |
return gulp.src( 'assets/style-guide/stylesheets/style-guide.scss' ) | |
.pipe( sass( { style: 'expanded' } ).on( 'error', sass.logError ) ) | |
.on( 'error', function ( err ) { | |
console.error( 'Error!', err.message ); | |
} ) | |
.pipe( gulp.dest( 'assets/style-guide' ) ) | |
}); | |
// Watch files for changes | |
gulp.task( 'watch', function() { | |
livereload.listen(); | |
gulp.watch( 'assets/stylesheets/**/*.scss', ['styles'] ); | |
gulp.watch( 'assets/js/**/*.js', ['scripts'] ); | |
gulp.watch( 'assets/svg/icons/*', ['icons'] ); | |
gulp.watch( 'assets/style-guide/**/*.scss', ['style-guide'] ); | |
}); | |
// Default Task | |
gulp.task( 'default', ['styles', 'scripts', 'icons', 'style-guide', 'watch'] ); |
This file contains 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": "themeslug", | |
"version": "1.0.0", | |
"description": "Automattic Team 51 strike project for xxx.org", | |
"main": "gulpfile.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://github.com/a8cteam51/*" | |
}, | |
"keywords": [ | |
"wordpress", | |
"theme", | |
"strike" | |
], | |
"author": "Automattic, Inc - Team 51 (http://automattic.com)", | |
"license": "GPL-2.0+", | |
"bugs": { | |
"url": "https://github.com/a8cteam51/*/issues" | |
}, | |
"homepage": "https://github.com/a8cteam51/*#readme", | |
"devDependencies": { | |
"gulp": "^3.9.0", | |
"gulp-autoprefixer": "^3.0.1", | |
"gulp-cache": "^0.3.0", | |
"gulp-cheerio": "^0.6.2", | |
"gulp-concat": "^2.6.0", | |
"gulp-csscomb": "^3.0.6", | |
"gulp-imagemin": "^2.3.0", | |
"gulp-jshint": "^1.11.2", | |
"gulp-livereload": "^3.8.1", | |
"gulp-notify": "^2.2.0", | |
"gulp-sass": "^2.1.1", | |
"gulp-sourcemaps": "^1.0.6", | |
"gulp-svgmin": "^1.2.0", | |
"gulp-svgstore": "^5.0.5", | |
"imagemin-pngquant": "^4.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment