const { src, dest, watch } = require('gulp'); const sync = require("browser-sync").create(); const uglify = require('gulp-uglify'); const rename = require('gulp-rename'); const cheerio = require('gulp-cheerio'); function streamHtml() { return src('src/*.html') .pipe(cheerio(function ($) { $('script').remove(); $('body').append('\n') })) .pipe(dest('public')); } function streamJS() { return src('src/js/*.js') .pipe(uglify()) .pipe(rename({ extname: '.min.js'})) .pipe(dest('public/js')); } function server() { sync.init({ server: { baseDir: "./public" } }); watch("./src/**/*.*").on("change", function() { sync.reload(); streamHtml(); streamJS(); }); } exports.streamHtml = streamHtml; exports.server = server; exports.streamJS = streamJS; exports.default = function() { watch('src/*.html', streamHtml); watch('src/js/*.js', streamJS); }