Created
August 28, 2017 13:59
-
-
Save Jursdotme/48823a4d5f80439e9d4d002938ed98f2 to your computer and use it in GitHub Desktop.
Undescores (_s) build tooling
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
// Gulp.js configuration | |
'use strict'; | |
const | |
// Gulp and plugins | |
gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
newer = require('gulp-newer'), | |
imagemin = require('gulp-imagemin'), | |
sass = require('gulp-sass'), | |
postcss = require('gulp-postcss'), | |
deporder = require('gulp-deporder'), | |
concat = require('gulp-concat'), | |
stripdebug = require('gulp-strip-debug'), | |
uglify = require('gulp-uglify') | |
; | |
// Browser-sync | |
var browsersync = false; | |
// PHP settings | |
const php = { | |
src : '**/*.php' | |
}; | |
// image settings | |
const images = { | |
src : 'images/**/*', | |
build : 'images/' | |
}; | |
// image processing | |
gulp.task('images', () => { | |
return gulp.src(images.src) | |
.pipe(newer(images.build)) | |
.pipe(imagemin()) | |
.pipe(gulp.dest(images.build)); | |
}); | |
// CSS settings | |
var css = { | |
src : 'sass/style.scss', | |
watch : 'sass/**/*', | |
build : '', | |
sassOpts: { | |
outputStyle : 'nested', | |
imagePath : images.build, | |
precision : 3, | |
errLogToConsole : true | |
}, | |
processors: [ | |
require('postcss-assets')({ | |
loadPaths: ['images/'], | |
basePath: '/', | |
baseUrl: '/wp-content/themes/nordex-food/' | |
}), | |
require('autoprefixer')({ | |
browsers: ['last 2 versions', '> 2%'] | |
}), | |
require('css-mqpacker'), | |
require('cssnano') | |
] | |
}; | |
// CSS processing | |
gulp.task('css', ['images'], () => { | |
return gulp.src(css.src) | |
.pipe(sass(css.sassOpts)) | |
.pipe(postcss(css.processors)) | |
.pipe(gulp.dest(css.build)) | |
.pipe(browsersync ? browsersync.reload({ stream: true }) : gutil.noop()); | |
}); | |
// JavaScript settings | |
const js = { | |
src : 'js/**/*', | |
build : 'js/', | |
filename : 'scripts.js' | |
}; | |
// JavaScript processing | |
gulp.task('js', () => { | |
return gulp.src(js.src) | |
.pipe(deporder()) | |
.pipe(concat(js.filename)) | |
.pipe(stripdebug()) | |
.pipe(uglify()) | |
.pipe(gulp.dest(js.build)) | |
.pipe(browsersync ? browsersync.reload({ stream: true }) : gutil.noop()); | |
}); | |
// run all tasks | |
gulp.task('build', ['css', 'js']); | |
// Browsersync options | |
const syncOpts = { | |
proxy : 'localhost', | |
files : '**/*', | |
open : false, | |
notify : false, | |
ghostMode : false, | |
ui: { | |
port: 8001 | |
} | |
}; | |
// browser-sync | |
gulp.task('browsersync', () => { | |
if (browsersync === false) { | |
browsersync = require('browser-sync').create(); | |
browsersync.init(syncOpts); | |
} | |
}); | |
// watch for file changes | |
gulp.task('watch', ['browsersync'], () => { | |
// page changes | |
gulp.watch(php.src, ['php'], browsersync ? browsersync.reload : {}); | |
// image changes | |
gulp.watch(images.src, ['images']); | |
// CSS changes | |
gulp.watch(css.watch, ['css']); | |
// JavaScript main changes | |
gulp.watch(js.src, ['js']); | |
}); | |
// default task | |
gulp.task('default', ['build', '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": "project-name", | |
"version": "1.0.0", | |
"scripts": {}, | |
"devDependencies": { | |
"autoprefixer": "^7.1.3", | |
"browser-sync": "^2.18.13", | |
"css-mqpacker": "^6.0.1", | |
"cssnano": "^3.10.0", | |
"gulp": "^3.9.1", | |
"gulp-concat": "^2.6.1", | |
"gulp-deporder": "^1.1.0", | |
"gulp-imagemin": "^3.3.0", | |
"gulp-newer": "^1.3.0", | |
"gulp-postcss": "^7.0.0", | |
"gulp-sass": "^3.1.0", | |
"gulp-strip-debug": "^1.1.0", | |
"gulp-uglify": "^3.0.0", | |
"gulp-util": "^3.0.8", | |
"gulp-watch": "^4.3.11", | |
"postcss-assets": "^4.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment