Answer the question
In order to leave comments, you need to log in
What needs to be changed in gulpfile.js to give a tunnel (i.e. a link to open on another device)?
Hello.
I wrote server settings in gulpfile.js:
var config = {
server: {
baseDir: "./dist"
},
tunnel: true,
host: 'localhost',
port: 8080,
logPrefix: "MAX"
};
I run the gulp command and the error is:
$ gulp
[11:58:11] Using gulpfile ~\Desktop\site\gulpfile.js
[11:58:11] Starting 'default'...
[11:58:11] Starting ' build'...
[11:58:11] Starting 'webserver'...
[11:58:11] Starting 'watch'...
[11:58:11] Starting 'vendorCss:build'...
[ 11:58:11] Starting 'vendorJs:build'...
[11:58:11] Starting '
[11:58:11] Starting 'js:build'...
[11:58:11] Starting 'scss:build'...
[11:58:11] Starting 'css:build'...
[11 :58:11] Starting 'fonts:build'...
[11:58:11] Starting 'image:build'...
[MAX] 1 file changed (index.html)
[11:58:12] Starting ' js:build'...
[11:58:12] Starting 'js:build'...
[11:58:13] Starting 'css:build'...
[MAX] 2 files changed (bootstrap.min. js, jquery.min.js)
[MAX] 2 files changed (bootstrap.min.js, jquery.min.js)
[MAX] 1 file changed (bootstrap.min.css)
[11:58:15] gulp-imagemin : Minified 4 images (saved 47.4 kB - 1.5%)
[MAX] 4 files changed (1.jpg, 2.jpg, gorod_vid_sverhu_zakat_128509_1600x900.jpg, nochnoj_gorod_arhitektura_dlitelnoe_vozdejstvie_135638_1600x900.jpg)
[MAX] Reloading Browsers... (buffered 7 events)
[11:58:16] 'webserver'3 errored
[11:58:16] TypeError: Cannot read property 'sockets' of undefined
at EventEmitter.browser:reload (C:\Users\User\Desktop\site\node_modules\browser-sync\dist\internal-events.js:20 :19)
at EventEmitter.emit (events.js:194:15)
at EventEmitter.emit (domain.js:459:23)
at AnonymousObserver._onNext (C:\Users\User\Desktop\site\node_modules\browser-sync \dist\internal-events.js:95:23)
at AnonymousObserver.Rx.AnonymousObserver.AnonymousObserver.next (C:\Users\User\Desktop\site\node_modules\rx\dist\rx.js:1828:12)
at AnonymousObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (C :\Users\User\Desktop\site\node_modules\rx\dist\rx.js:1762:31)
at AnonymousObserver.tryCatcher (C:\Users\User\Desktop\site\node_modules\rx\dist\rx.js: 63:31)
at AutoDetachObserverPrototype.next (C:\Users\User\Desktop\site\node_modules\rx\dist\rx.js:5883:51)
at AutoDetachObserver.Rx.internals.AbstractObserver.AbstractObserver.onNext (C:\ Users\User\Desktop\site\node_modules\rx\dist\rx.js:1762:31)
at InnerObserver.next (C:\Users\User\Desktop\site\node_modules\rx\dist\rx.js:5409: 14)
[11:58:16] 'default' errored after 4.53 s
[11:58:16] The following tasks did not complete: build, watch, , vendorCss:build, vendorJs:build, html:build, js:build, scss:build, css:build, fonts:build, image:build , js:build, js:build, css:build
[11:58:16] Did you forget to signal async completion?
But when I remove everything from the server settings, except:
var config = {
server: {
baseDir: "./dist"
}
};
and I delete everything from dist, then the browser opens. But there is no link (Tunnel) in the console, but I need it.
My gulpfile.js:
'use strict';
var gulp = require('gulp'),
mainBowerFiles = require('main-bower-files'),
watch = require('gulp-watch'),
prefixer = require('
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
cleanCSS = require('gulp-clean-css'),
imagemin = require( 'gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
rimraf = require('rimraf'),
browserSync = require('browser-sync'),
reload = browserSync.reload;
var path = {
vendor: {
js: 'app/js/',
css: 'app/css/'
},
dist: { //Here we will specify where to put the files ready after assembly
html: 'dist/',
js: ' dist/js/',
img: 'dist/img/',
fonts: 'dist/fonts/'
},
app: { //Paths to source from
html: 'app/*.html', //The src/*.html syntax tells gulp that we we want to take all files with the extension .html
js: 'app/js/*.js',//In styles and scripts, we only need main files
scss: 'app/css/*.scss',
css: 'app/css/ *.css',
img: 'app/img/**/*.*', //Syntax img/**/*.* means - take all files of all extensions from the folder and subdirectories
fonts: 'app/fonts /**/*.*'
},
watch: { //Here we specify which files we want to watch for changes
html: 'app/**/*.html',
js: 'app/js/**/*.js',
scss: 'app/css/**/*.scss',
css: 'app/css/**/*.css',
img: 'app/img/**/*.*',
fonts: 'app/ fonts/**/*.*'
},
clean: './dist'
};
var config = {
server: {
baseDir: "./dist"
},
tunnel: true,
host: 'localhost',
port: 8080,
logPrefix: "MAX"
};
gulp.task('vendorJs:build', function () {
gulp.src( mainBowerFiles('**/*.js') ) //Select files from the required path
.pipe(gulp.dest(path.vendor.js) ) //Spit out the finished file in app
});
gulp.task('vendorCss:build',
gulp.src( mainBowerFiles('**/*.css') ) //Select files from the required path
.pipe(gulp.dest(path.vendor.css)) //And in app
});
gulp.task('html:build', function () {
gulp.src(path.app.html) //Select files from the desired path
.pipe(gulp.dest(path.dist.html)) //Spit them out into build folder
.pipe(reload({stream: true})); //And reload our server for updates
});
gulp.task('js:build', function () {
gulp.src(path.app.js) //Find our main file
.pipe(sourcemaps.init()) //Initialize sourcemap
.pipe(uglify()) //Compress our js
.pipe(sourcemaps.write()) //Write maps
.pipe(gulp.dest(path.dist.js)) //Spit the finished file into build
.pipe(reload({stream: true})); //And restart the server
});
gulp.task('scss:build', function () {
gulp.src(path.app.scss) //Select our main.scss
.pipe(sourcemaps.init()) //Same as with js
. pipe(sass()) //Compile
.pipe(prefixer()) //Add vendor prefixes
.pipe(cleanCSS()) //Compress
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.dist .scss)) //And in build
.pipe(reload({stream: true}));
});
gulp.task('css:build', function () {
gulp.src(path.app.css) //Select our main.css
.pipe(sourcemaps.init()) //Same as js
.pipe(gulp.dest(path.dist.css)) //And in build
.pipe(reload({stream: true}));
});
gulp.task('image:build', function () {
gulp.src(path.app.img) //Select our images
.pipe(imagemin({ //Compress them
progressive: true,
svgoPlugins: [{removeViewBox: false }],
use: [pngquant()],
interlaced: true
}))
.pipe(gulp.dest(path.dist.img)) //And throw in build
.pipe(reload({stream: true}));
});
gulp.task('fonts:build', function() {
gulp.src(path.app.fonts)
.pipe(gulp.dest(path.dist.fonts))
});
gulp.task('build', gulp.series(gulp.parallel(
'vendorCss:build',
'vendorJs:build',
'html:build',
'js:build',
'scss:build',
'css:build ',
'fonts:build',
'image:build'
)));
gulp.task('watch', function(){
watch([path.watch.html], gulp.parallel('html:build'));
watch([path.watch.scss], gulp.parallel('scss :build'));
watch([path.watch.css], gulp.parallel('css:build'));
watch([path.watch.js], gulp.parallel('js:build'));
watch([path.watch.img], gulp.
watch([path.watch.fonts],gulp.parallel('fonts:build'))
});
gulp.task('webserver', function () {
browserSync(config);
});
gulp.task('clean', function (cb) {
rimraf(path.clean, cb);
});
gulp.task('default', gulp.parallel('build', 'webserver', 'watch'));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question