var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var autoprefixer = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
gulp.task('browser-sync', function(done) {
browserSync.init({
server: {
baseDir: './out'
},
notify: false
});
browserSync.watch('out/').on('change', browserSync.reload);
done()
});
gulp.task('sass', function(done){
gulp.src('app/scss/*.scss')
.pipe(plumber({
errorHandler : function(err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sass({errLogToConsole: true}))
.pipe(sass({outputStyle: 'compact'}))
.pipe(autoprefixer({
browsers: ['last 4 versions'],
cascade: false
}))
.pipe(gulp.dest('out/assets/css'))
.pipe(browserSync.reload({stream: true}));
done()
});
gulp.task('watch', gulp.series('sass', 'browser-sync', function(done) {
gulp.watch('app/**/*.*', gulp.series('sass'));
done()
}));
function compileJade(done) {
gulp.src('src/jade/*.jade')
.pipe(plumber())
.pipe(jade())
.pipe(gulp.dest('build/'))
.pipe(server.reload({ stream: true }));
done()
}
function compileScss(done) {
gulp.src([
'src/sass/*.scss',
'!src/sass/mixins.scss',
'!src/sass/normalize.scss',
'!src/sass/variable.scss'
])
.pipe(plumber())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(postcss([
autoprefixer({
browsers: [
"last 1 version",
"last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Opera versions",
"last 2 Edge versions"
],
grid: true
})
]))
.pipe(gcmq())
.pipe(minify())
.pipe(gulp.dest('build/css'))
.pipe(server.reload({ stream: true }));
done()
}
function compileScripts(done) {
gulp.src('src/js/*.js')
.pipe(plumber())
.pipe(jsmin())
.pipe(gulp.dest('build/js/'))
.pipe(server.reload({ stream: true }));
done()
}
function makeHash(done) {
gulp.src('build/index.html')
.pipe(hash())
.pipe(gulp.dest('build'));
done()
}
function watcher(done) {
server.init({
server: 'build'
});
gulp.watch('src/sass/**/*.scss', gulp.series(compileScss, makeHash));
gulp.watch('src/**/*.jade', gulp.series(compileJade, makeHash));
gulp.watch('src/js/*.js', gulp.series(compileScripts, makeHash));
done()
}
module.exports = {
default: watcher,
watcher,
build: gulp.series(
compileJade,
compileScss,
compileScripts,
makeHash
),
jade: compileJade,
style: compileScss,
script: compileScripts,
hash: makeHash
}
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
gulp.task('sass', function(done) {
gulp.src("scr/scss/*.scss")
.pipe(sass())
.pipe(gulp.dest("scr/css"))
.pipe(browserSync.stream());
done();
});
gulp.task('serve', function(done) {
browserSync.init({
server: "src/"
});
gulp.watch("scr/sass/*.sass", gulp.series('sass'));
gulp.watch("scr/*.html").on('change', () => {
browserSync.reload();
done();
});
done();
});
gulp.task('default', gulp.series('sass', 'serve'));
gulp.task('watch', function() {
gulp.watch([paths.pug.load[0],paths.pug.load[1]], gulp.series(
'pug:build',
done => {
reload();
done();
}
));
});
И что за новые возможности series, parallel появились?эта загадка человечества, разгадать которую можно, прочитав документацию
var $ = require('jquery');
require('jquery-ui/ui/widgets/slider');
$('#id').slider();
const gulp = require('gulp');
const revReplace = require('gulp-rev-replace');
gulp.task('revision', (done) => {
const manifestFile = gulp.src('path/to/manifest.json');
gulp.src('public/*.html')
.pipe(revReplace({manifest: manifestFile}))
.pipe(gulp.dest('public'));
done();
});