Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Assets pipeline via Gulp
# ------------
# Task runners
# ------------
# Gulp builder
gulp = require 'gulp'
# Run tasks one by one
runSeq = require 'run-sequence'
# ------------
# Gulp plugins
# ------------
# Error notification
plumber = require 'gulp-plumber'
# Native notifications
notify = require 'gulp-notify'
# File concatenator
concat = require 'gulp-concat'
# Rename files
rename = require 'gulp-rename'
# Ignore files
ignore = require 'gulp-ignore'
# Remove files
clean = require 'gulp-clean'
# Coffeescript compiler
coffee = require 'gulp-coffee'
# Sass compiler
sass = require 'gulp-sass'
# CSS prefixes
prefix = require 'gulp-autoprefixer'
# CSS minifier
minify = require 'gulp-clean-css'
# Assets revisioning
rev = require 'gulp-rev'
revCol = require 'gulp-rev-collector'
# Compressor
zopfli = require 'gulp-zopfli'
# ------------
# Assets paths
# ------------
basePath = './themes/roemwp/'
buildPath = './build/'
paths =
compress: ["#{basePath}app.min-*"]
build:
dest: buildPath
css: ["#{buildPath}app.css"]
min: "#{basePath}app.min.css"
styles:
dir: ["#{basePath}sass/**"]
source: ["#{basePath}sass/app.sass"]
dest: basePath
scripts:
source: ["#{basePath}js/*.coffee"]
dest: "#{basePath}js"
templates:
source: ["#{basePath}rev-manifest.json", "#{basePath}header.php"]
dest: basePath
# --------------
# Error handling
# --------------
plumberCfg = errorHandler: (error) ->
console.log error
notify.onError("Error: <%= error.message %>").apply @, arguments
# ----------
# Base tasks
# ----------
gulp.task 'clean', () ->
gulp.src paths.compress
.pipe plumber plumberCfg
.pipe clean()
gulp.task 'css:compile', () ->
gulp.src paths.styles.source
.pipe plumber plumberCfg
.pipe sass
sourceComments: 'normal'
.pipe gulp.dest paths.build.dest
gulp.task 'css:prefixify', () ->
gulp.src paths.build.css
.pipe plumber plumberCfg
.pipe prefix 'last 2 version'
.pipe gulp.dest paths.build.dest
gulp.task 'css:minify', () ->
gulp.src paths.build.css
.pipe plumber plumberCfg
.pipe rename
suffix: '.min'
.pipe minify()
.pipe gulp.dest paths.build.dest
gulp.task 'scripts', () ->
gulp.src paths.scripts.source
.pipe plumber plumberCfg
.pipe coffee()
.pipe gulp.dest paths.scripts.dest
gulp.task 'compress', () ->
gulp.src paths.compress
.pipe plumber plumberCfg
.pipe zopfli()
.pipe gulp.dest paths.styles.dest
gulp.task 'revisionize', () ->
gulp.src "#{paths.build.dest}/*.min.css"
.pipe plumber plumberCfg
.pipe rev()
.pipe gulp.dest paths.styles.dest
.pipe rev.manifest()
.pipe gulp.dest paths.styles.dest
gulp.task 'templates:update', () ->
gulp.src paths.templates.source
.pipe revCol
replaceReved: true
.pipe gulp.dest paths.templates.dest
# -------------
# Complex tasks
# -------------
gulp.task 'watch', ->
gulp.watch paths.styles.dir, ['styles']
gulp.watch paths.scripts.source, ['scripts']
gulp.task 'styles', (callback) ->
runSeq 'css:compile',
'css:prefixify',
['css:minify', 'clean'],
'revisionize',
['templates:update', 'compress'],
callback
gulp.task 'compile', ['styles', 'scripts']
gulp.task 'default', (callback) ->
runSeq 'compile', 'watch', callback
{
"name": "RoemWP",
"version": "0.0.1",
"description": "Roem.ru Wordpress theme (ver. 3)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://bitbucket.org/rtf/wproem/"
},
"keywords": [
"Wordpress",
"roem.ru"
],
"author": "Nick Kugaevsky",
"license": "MIT",
"bugs": {
"url": "http://task.roem.ru/projects/roem/issues"
},
"homepage": "http://roem.ru",
"devDependencies": {
"bower": "^1.3.12",
"coffee-script": "^1.8.0",
"gulp": "^3.8.10",
"gulp-autoprefixer": "^1.0.1",
"gulp-clean": "^0.3.1",
"gulp-clean-css": "^1.0.2",
"gulp-coffee": "^2.2.0",
"gulp-concat": "^2.4.1",
"gulp-ignore": "^1.2.1",
"gulp-notify": "^2.0.1",
"gulp-plumber": "^0.6.6",
"gulp-rename": "^1.2.0",
"gulp-rev": "^2.0.1",
"gulp-rev-collector": "^0.1.2",
"gulp-sass": "^1.1.0",
"gulp-zopfli": "^0.1.1",
"run-sequence": "^1.0.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.