Why doesn't Gulp browser-sync open the browser?
When I write Gulp watch, all functions work except browser-sync. I tried to disable the antivirus, but without results.
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
var browserSync = require('browser-sync').create();
let config = {
src: 'src',
css: {
src: '/precss/**/*.css',
dest: '/css'
}
};
gulp.task('build', function() {
gulp.src(config.src + config.css.src)
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(cleanCSS())
.pipe(gulp.dest(config.src + config.css.dest))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('watch', ['browserSync'], function() {
gulp.watch(config.src + config.css.src, ['build']);
});
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: config.src
}
});
});
The answer is not at all obvious. I was able to do it when I start the terminal without administrator rights. No code corrections
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.