Skip to content

Instantly share code, notes, and snippets.

@s-belichenko
Last active September 30, 2018 21:56
Show Gist options
  • Save s-belichenko/844cd0a08e69a8887526743b7a75a792 to your computer and use it in GitHub Desktop.
Save s-belichenko/844cd0a08e69a8887526743b7a75a792 to your computer and use it in GitHub Desktop.
JS (ECMAScript 5.1) + CSS
// Gulp plugins
var gulp = require('gulp'),
minifyCSS = require('gulp-csso'),
concat = require('gulp-concat'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
stripDebug = require('gulp-strip-debug');
// env variables
var front_folder = 'web',
css_paths = [
'resources/assets/web/css/*/*.css',
'resources/assets/web/css/*.css'
],
js_paths = [
'resources/assets/web/js/script.js',
'resources/assets/web/js/*.js',
'resources/assets/web/js/*/*.js'
];
// CSS
gulp.task('css-dev', function () {
return gulp.src(css_paths)
.pipe(sourcemaps.init())
.pipe(minifyCSS())
.pipe(concat(front_folder + '.min.css'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('web/css/'))
});
gulp.task('css-prod', function () {
return gulp.src(css_paths)
.pipe(minifyCSS())
.pipe(concat(front_folder + '.min.css'))
.pipe(gulp.dest('web/css/'))
});
// JS
gulp.task('js-dev', function () {
return gulp.src(js_paths)
.pipe(sourcemaps.init())
.pipe(concat(front_folder + '.min.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('web/js'))
});
gulp.task("js-prod", function () {
return gulp.src(js_paths)
.pipe(concat(front_folder + '.min.js'))
.pipe(stripDebug())
.pipe(gulp.dest('web/js'))
});
gulp.task('js-compress', function () {
gulp.src(front_folder + '/js/web.min.js')
.pipe(uglify())
.pipe(gulp.dest('web/js'));
});
// Watchers
gulp.task('css:watch', function () {
gulp.watch(css_paths, ['css-dev']);
});
gulp.task('js:watch', function () {
gulp.watch(js_paths, ['js-dev']);
});
// Default
gulp.task('default', ['css-prod', 'js-prod']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment