Open QuintonC opened 5 years ago
Hello,
Watch my issue :
1637
Nothing that was in your solution worked for me. My project runs locally on https://localhost:3000 and when I try to implement ANY of your changes it pushes me to https://localhost:3001 and doesn't work for anything at all.
So I've changed my watch to the following:
//Watch for any changes to the js files.
gulp.watch('./wwwroot/js/source/*.js', ['js-watch']);
Added this task:
/**
* Defining function for watching Javascript files. This will reload the browser when complete.
*/
gulp.task('js-watch', ['compileJS'], function (done) {
browserSync.reload();
done();
});
And still nothing. I get the "Reloading Browsers..." message, but nothing happens.
I've never had a problem with Browsersync before and often use it for Wordpress development, but now that I'm using it for a .net project it's giving me such a headache trying to get it to work right. I've been battling this issue for well over a week and it's incredibly frustrating that I can't seem to get any answers anywhere.
Hello, Check in your code if browsersync inject the script for reloading like that (the body tag is needed):
<script async="" id="__bs_script__" src="http://localhost:3000/browser-sync/browser-sync-client.js?v=2.26.3"></script>
In pipe you just need .pipe(browserSync.stream()); normally after the dest. And in proxy config you put your vhost or your subdirectories browsersync create for you the localhost:3000.
It is not injecting the script into my source. I have a body tag, but once again.. I'm thinking this is probably more specific to a .net issue.
My reasoning for that is that the Index.cshtml page which loads by default does not have a body tag, but the shared template that it loads does have a body tag. I don't know if that has something to do with it or not, but I would assume that it's possible.
Here are the only four scripts included in my code when inspecting:
I've tried streaming numerous different ways.
gulp.task('sass', function () {
return gulp.src('./wwwroot/sass/main.scss')
.pipe(sassGlob())
.pipe(sass().on('error', function (err) {
console.log('Sass Error:', err.toString());
notifier.notify({
'title': 'Gettin\' Sassy 💁♀️',
'message': 'You goofed. Check your terminal window for more information.'
});
this.emit("end");
}))
.pipe(postcss([require('autoprefixer')]))
.pipe(
autoprefixer({
browsers: ['last 2 versions'],
cascade: false
})
)
.pipe(
through.obj(function(chunk, enc, cb) {
cb(null, chunk)
})
)
.pipe(cleanCSS({compatibility: 'ie8',
level: 2}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./wwwroot/css'))
.pipe(browserSync.reload({stream: true}));
// .pipe(reload({stream: true}));
});
Also, it's worth mentioning that if I set the app to run on localhost:3050, then set up Browsersync to proxy that address it will not load any information on localhost:3000 (the bs port).
If I run off of a serve task it will not work either.
Below reload function works for me instead of direct call browsersync.reload. I got the exact issue like you mentioned.
const browsersync = require('browser-sync').create();
function reload(cb) {
browsersync.reload();
cb();
}
watch([files.scssPath, files.jsPath],
series(
parallel(scssTask, jsTask),
reload
)
);
Issue details
I'm having trouble getting Browsersync to reload the browser or inject any css changes. I've used Browsersync before on numerous Wordpress projects, but never in a .net core project via Visual Studio.
My project runs on localhost:3000, which has never been an issue before (even when doing wp development), but for some reason, this is just different and I can't figure out if I'm missing something or if I have misconfigured something, but everything seems to be there.
Terminal window output:
Steps to reproduce/test case
Just running gulp in the terminal window to start the process is what triggers the issue.
Please specify which version of Browsersync, node and npm you're running
Affected platforms
Browsersync use-case
for all other use-cases, (gulp, grunt etc), please show us exactly how you're using Browsersync
Gulpfile.js: