Skip to content

Instantly share code, notes, and snippets.

@s-belichenko
Last active September 30, 2018 21:55
Show Gist options
  • Save s-belichenko/c0e825b79a50035c9eef0b83a6bb3ec6 to your computer and use it in GitHub Desktop.
Save s-belichenko/c0e825b79a50035c9eef0b83a6bb3ec6 to your computer and use it in GitHub Desktop.
JS (ECMAScript 5.1) + CSS + Sass
// Gulp plugins
var gulp = require('gulp'),
minifyCSS = require('gulp-csso'),
merge = require('merge-stream'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
stripDebug = require('gulp-strip-debug');
// env variables
var build_folder = 'public/wp-content/themes/ravapanel/',
css_paths = [
'assets/css/*/*.css',
'assets/css/*.css'
],
sass_paths = [
'assets/sass/**/*.sass'
],
js_paths = [
'assets/js/script.js',
'assets/js/*/*.js',
'assets/js/*.js'
];
// Styles
gulp.task('styles-dev', function () {
var sassStream = gulp.src(sass_paths)
.pipe(sass())
.pipe(concat('scss-files.scss'))
;
var cssStream = gulp.src(css_paths)
.pipe(concat('css-files.css'))
;
return merge(sassStream, cssStream)
.pipe(sourcemaps.init())
.pipe(minifyCSS())
.pipe(concat('style.min.css'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(build_folder + '/css/'));
});
gulp.task('styles-prod', function () {
var sassStream = gulp.src(sass_paths)
.pipe(sass())
.pipe(concat('scss-files.scss'))
;
var cssStream = gulp.src(css_paths)
.pipe(concat('css-files.css'))
;
return merge(sassStream, cssStream)
.pipe(minifyCSS())
.pipe(concat('style.min.css'))
.pipe(gulp.dest(build_folder + '/css/'));
});
// JS
gulp.task('js-dev', function () {
return gulp.src(js_paths)
.pipe(sourcemaps.init())
.pipe(concat('script.min.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(build_folder + '/js'))
});
gulp.task("js-prod", function () {
return gulp.src(js_paths)
.pipe(concat('script.min.js'))
.pipe(stripDebug())
.pipe(gulp.dest(build_folder + '/js'))
});
gulp.task('js-compress', function () {
gulp.src(build_folder + '/js/script.min.js')
.pipe(uglify())
.pipe(gulp.dest(build_folder + '/js'));
});
// Watchers
gulp.task('js:watch', function () {
gulp.watch(js_paths, ['js-dev']);
});
gulp.task('styles:watch', function () {
gulp.watch(css_paths, ['styles-dev']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment