const gulp = require('gulp');
const sass = require('gulp-sass');
const twig = require('gulp-twig');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const plumber = require('gulp-plumber');
const sequence = require('gulp-sequence');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const changed = require('gulp-changed-in-place');
const bs = require('browser-sync').create();
gulp.task('sass', function () {
return gulp.src([
'./node_modules/normalize.css/normalize.css',
'./node_modules/tiny-slider/dist/tiny-slider.css',
'./src/sass/**/*.scss',
])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'nested' }))
.pipe(autoprefixer())
.pipe(concat('main.css'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./public_html/design/'))
.pipe(bs.stream())
;
});
gulp.task('js:vendor', function (done) {
gulp.src([
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/whatwg-fetch/dist/fetch.umd.js',
'./node_modules/tiny-slider/dist/min/tiny-slider.js',
])
.pipe(plumber())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat('vendor.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./public_html/design/'))
.on('end', done)
;
});
gulp.task('js', function (done) {
gulp.src([
'./src/js/main.js',
'./src/js/**/*.js',
])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(concat('main.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./public_html/design/'))
.on('end', function () {
bs.reload();
done();
})
;
});
gulp.task('twig', function (done) {
gulp.src([
'./src/twig/*.twig',
])
.pipe(plumber())
.pipe(twig({
base: [__dirname],
}))
.pipe(changed({ firstPass: true }))
.pipe(gulp.dest('./public_html/'))
.on('end', function () {
bs.reload();
done();
})
;
});
gulp.task('serve', function () {
bs.init({
ui: false,
//proxy: 'mysite.local',
server : './public_html',
browser: ['chrome'],
});
// gulp.watch('./public_html/*.html').on('change', bs.reload);
gulp.watch('./src/sass/**/*.scss', ['sass']);
gulp.watch('./src/js/**/*.js', ['js']);
gulp.watch('./src/twig/**/*.twig', ['twig']);
});
gulp.task('default', sequence(['twig', 'sass', 'js', 'js:vendor'], 'serve'));