Talk to me, good afternoon, I have the following problem:
I have the following tasks in my gulpfile.js
var gulp = require('gulp'),
cssmin = require('gulp-cssmin'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
pump = require('pump'),
concat = require('gulp-concat'),
runSequence = require('run-sequence'),
browserSync = require('browser-sync').create(),
clear = require('rimraf'),
gutil = require('gulp-util');
const arg = (argList => {
let arg = {}, a, opt, thisOpt, curOpt;
for (a = 0; a < argList.length; a++) {
thisOpt = argList[a].trim();
opt = thisOpt.replace(/^\-+/, '');
if (opt === thisOpt) {
// argument value
if (curOpt) arg[curOpt] = opt;
curOpt = null;
}
else {
// argument name
curOpt = opt;
arg[curOpt] = true;
}
}
return arg;
})(process.argv);
// Default
gulp.task('default', ['clear'], function (callback) {
let tasks = ['cssmin', 'gulp', 'watch'];
if (!arg.nobrowser) {
tasks.push('browser-sync');
}
runSequence('uglify', tasks, 'watch', callback);
});
// Debug
gulp.task('debug', function (callback) {
runSequence(
['browser-sync-debug', 'watch'],
callback);
});
gulp.task('clear', function (cb) {
clear('./dist/**/**', cb);
console.log("Limpando a pasta dist");
});
// Browser Sync
gulp.task('browser-sync', function () {
browserSync.init({
port: 8000,
host: '0.0.0.0',
server: {
baseDir: "./dist"
},
open: false
});
});
gulp.task('browser-sync-debug', function () {
browserSync.init({
port: 8000,
https: arg.https ? arg.https : false,
ghostMode: !!arg.nogost,
server: {
baseDir: "./source"
},
open: false
});
});
// MINIFY CSS (minificar CSS)
// importa o modulo 'cssmin' e cria uma função com o mesmo, para: minificar, renomear, concatenar tudo em um arquivo, e jogar no dist
//----------------------------------------------------------------------
gulp.task('cssmin', function () {
gulp.src('source/assets/css/**/*.css')
.pipe(cssmin())
// .pipe(rename({suffix: '.min'}))
.pipe(concat('styles.min.css'))
.pipe(gulp.dest('dist/assets/css/'));
});
// Uglify
gulp.task('uglify', function (cb) {
pump([
gulp.src(['source/**/*.js']),
uglify()
.pipe(gulp.dest('./dist'))
],
cb
);
});
// Move files
gulp.task('gulp', function () {
console.log("Estou movendo os arquivos para o dist :D ...");
gulp.src("source/**/*")
.pipe(gulp.dest('dist'));
});
// Watch
gulp.task('watch', function () {
function reportChange(event) {
console.log('Event type: ' + event.type);
console.log('Event path: ' + event.path);
}
gulp.watch('source/assets/css/**/*.css', { interval: 2000 }, ['cssmin', 'gulp']).on('change', reportChange);
gulp.watch('index.html', { interval: 2000 }, ['gulp']).on('change', reportChange);
gulp.watch(['source/**/*.js', 'source/**/*.html'], { interval: 2000 }, ['gulp']).on('change', (process.env.BROWSER_SYNC === 'N' || arg.sync == false) ? gutil.noop : browserSync.reload, reportChange);
});
When I run the command gulp
all right, but when I try to run the command gulp --nobrowser
which is to start the gulp without the browser sync, it starts however does not end and does not exit that load or the cow cough
[16:42:58] Using gulpfile ~/Área de Trabalho/sistema-bilhetagem/sbe-web-backoffice/gulpfile.js
[16:42:58] Starting 'clear'...
Limpando a pasta dist
[16:42:59] Finished 'clear' after 1.56 s
[16:42:59] Starting 'default'...
[16:42:59] Starting 'uglify'...
[16:43:00] Finished 'uglify' after 1.03 s
[16:43:00] Starting 'cssmin'...
[16:43:00] Finished 'cssmin' after 1.44 ms
[16:43:00] Starting 'gulp'...
Estou movendo os arquivos para o dist :D ...
[16:43:00] Finished 'gulp' after 474 μs
[16:43:00] Starting 'watch'...
[16:43:01] Finished 'watch' after 852 ms
[16:43:01] Starting 'watch'...
[16:43:02] Finished 'watch' after 705 ms
[16:43:02] Finished 'default' after 2.59 s
Can anyone help me? I'm grateful to you!