Skip to content

Instantly share code, notes, and snippets.

@meddokss
Last active April 30, 2017 06:00
Show Gist options
  • Save meddokss/e44488a80a6cdceb992fb13bec684d1b to your computer and use it in GitHub Desktop.
Save meddokss/e44488a80a6cdceb992fb13bec684d1b to your computer and use it in GitHub Desktop.
Gulp Task WATCH SASS, SCSS
var gulp = require('gulp'),
gutil = require('gulp-util' ),
sass = require('gulp-sass'),
babel = require('gulp-babel'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cleanCSS = require('gulp-clean-css'),
rename = require('gulp-rename'),
del = require('del'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer'),
ftp = require('vinyl-ftp'),
notify = require("gulp-notify");
// Скрипты проекта
gulp.task('common-js', function() {
return gulp.src([
'app/js/common.js',
])
.pipe(babel({
presets: ['es2015']
}))
.pipe(concat('common.min.js'))
.pipe(uglify())
.pipe(gulp.dest('app/js'));
});
gulp.task('js', ['common-js'], function() {
return gulp.src([
'app/libs/jquery/dist/jquery.min.js',
'app/libs/mmenu/jquery.mmenu.all.min.js',
'app/libs/OwlCarousel2-2.2.1/owl.carousel.min.js',
'app/js/common.min.js', // Всегда в конце
])
.pipe(concat('scripts.min.js'))
.pipe(uglify()) // Минимизировать весь js (на выбор)
.pipe(gulp.dest('app/js'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: 'app'
},
notify: false,
// tunnel: true,
// tunnel: "projectmane", //Demonstration page: http://projectmane.localtunnel.me
});
});
gulp.task('sass', function() {
return gulp.src(['app/sass/**/*.sass', 'app/sass/**/*.scss'])
.pipe(sass({outputStyle: 'expand'}).on("error", notify.onError()))
.pipe(rename({suffix: '.min', prefix : ''}))
.pipe(autoprefixer(['last 15 versions']))
// .pipe(cleanCSS()) // Опционально, закомментировать при отладке
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('watch', ['sass', 'js', 'browser-sync'], function() {
gulp.watch(['app/sass/**/*.sass', 'app/sass/**/*.scss', 'app/libs/**/*.scss' ], ['sass']);
gulp.watch(['libs/**/*.js', 'app/js/common.js'], ['js']);
gulp.watch('app/*.html', browserSync.reload);
});
gulp.task('imagemin', function() {
return gulp.src('app/img/**/*')
.pipe(cache(imagemin()))
.pipe(gulp.dest('dist/img'));
});
gulp.task('build', ['removedist', 'imagemin', 'sass', 'js'], function() {
var buildFiles = gulp.src([
'app/*.html',
'app/.htaccess',
]).pipe(gulp.dest('dist'));
var buildCss = gulp.src([
'app/css/main.min.css',
]).pipe(gulp.dest('dist/css'));
var buildJs = gulp.src([
'app/js/scripts.min.js',
]).pipe(gulp.dest('dist/js'));
var buildFonts = gulp.src([
'app/fonts/**/*',
]).pipe(gulp.dest('dist/fonts'));
});
gulp.task('deploy', function() {
var conn = ftp.create({
host: 'hostname.com',
user: 'username',
password: 'userpassword',
parallel: 10,
log: gutil.log
});
var globs = [
'dist/**',
'dist/.htaccess',
];
return gulp.src(globs, {buffer: false})
.pipe(conn.dest('/path/to/folder/on/server'));
});
gulp.task('removedist', function() { return del.sync('dist'); });
gulp.task('clearcache', function () { return cache.clearAll(); });
gulp.task('default', ['watch']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment