const gulp_run = require("gulp"),
gulpsass = require("gulp-sass"),
watch = require("gulp-watch");
const { clean } = require("semver");
const path ={
templates:{
src:"src/templates/*.html",
dest:"build",
watch:"src/templates/**/*.html",
},
styles:{
src:"src/styles/main.scss",
dest:"build/assets/css",
watch:"src/styles/parsials/**/*.scss",
},
fonts:{
src:"src/fonts/*",
dest:"build",
watch:"src/fonts/**/*",
},
images:{
src:"src/images/*",
dest:"build",
watch:"src/images/**/*",
},
}
gulp.task('templates', function(){
return gulp
.src(path.templates.src)
.pipe(gulp.dest.path.templates.dest)
.on('end', browserSync.reload);
})
gulp.task('styles', function(){
return gulp
.src(path.styles.src)
.pipe(gulp.dest.path.styles.dest)
.pipe(sass())
.on('end', browserSync.reload);
})
gulp.task('fonts', function(){
return gulp
.src(path.fonts.src)
.pipe(gulp.dest.path.fots.dest)
.on('end', browserSync.reload);
})
gulp.task('images', function(){
return gulp
.src(path.images.src)
.pipe(gulp.dest.path.images.dest)
.on('end', browserSync.reload);
})
gulp.task('watch', function(){
return new Promise((res,rej)=>{watch(path.templates.watch,gulp.series("templates"));
watch(path.styles.watch,gulp.series("styles"));
watch(path.images.watch,gulp.series("images"));
});
});
gulp.task('clean', function(){
return gulp.src('./build/*',{read: false}).pipe(clean());
});
gulp.task('serve', function(){
return new Promise((res,rej)=>{
browserSync.init({
server: './build/', tunnel: true, port: 4200,
});
res();
});
});
npm install gulp sass browser-sync del --save-dev
// gulpfile.js
'use strict';
const { src, dest, lastRun, watch, series, parallel } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const browserSync = require('browser-sync').create();
const del = require('del');
const path = {
templates: {
src: 'src/templates/*.html',
dest: 'build',
watching: 'src/templates/**/*.html',
},
styles: {
src: 'src/styles/main.scss',
dest: 'build/assets/css',
watching: 'src/styles/parsials/**/*.scss',
},
fonts: {
src: 'src/fonts/*',
dest: 'build',
watching: 'src/fonts/**/*',
},
images: {
src: 'src/images/*',
dest: 'build',
watching: 'src/images/**/*',
},
};
function cleanup() {
return del([path.build]);
}
function server() {
browserSync.init({
server: {
baseDir: './build/',
},
port: 3004,
open: false,
notify: true,
browser: 'default',
online: true,
// logLevel: 'debug',
});
}
function templates() {
return src(path.templates.src)
.pipe(dest(path.templates.dest))
.on('end', browserSync.reload);
}
function styles() {
return src(path.styles.src)
.pipe(sass.sync())
.pipe(dest(path.styles.dest))
.on('end', browserSync.reload);
}
function watching() {
watch(path.templates.watching, series('templates'));
watch(path.styles.watching, series('styles'));
watch(path.images.watching, series('images'));
}
exports.default = series(templates, styles);
exports.development = series(cleanup, exports.default, parallel(watching, server));
// package.json добавить
.....
"scripts": {
"start": "gulp development",
},
.......
npm run start