Gulp浏览器同步无法与外部设备

时间:2016-08-25 17:51:37

标签: gulp gulp-browser-sync

想知道我是否能得到一些帮助。

我的网络开发环境在一台专用计算机上,然后我从我的Mac上通过SFTP / SSH进行实际工作。在开发计算机上启动时,我很难让Gulp的浏览器同步在我的Mac上运行。我在下面附上了我的gulp文件。我可以访问仪表板(:3001),但网站本身不会在浏览器同步中显示。有什么想法吗?

    // Include gulp
var gulp = require('gulp');
// Include Our Plugins
var sass = require('gulp-sass');
var uglifycss = require('gulp-uglifycss');

var browserSync = require('browser-sync').create();
var autoprefixer = require('gulp-autoprefixer');
var autoprefixerOptions = {
  browsers: ['Android >= 2.3',
    'BlackBerry >= 7',
    'Chrome >= 9',
    'Firefox >= 4',
    'Explorer >= 9',
    'iOS >= 5',
    'Opera >= 11',
    'Safari >= 5',
    'OperaMobile >= 11',
    'OperaMini >= 6',
    'ChromeAndroid >= 9',
    'FirefoxAndroid >= 4',
    'ExplorerMobile >= 9']
};


// Compile Our Sass
gulp.task('sass', function() {
    return gulp.src('scss/*.scss')
        .pipe(sass())
            .pipe(autoprefixer(autoprefixerOptions))
        .pipe(gulp.dest('./'));
});


// Initiate BrowserSync. Check for CSS changes and reload. Don't forget to change the proxy to the correct domain!
gulp.task('browser-sync', function (cb) {
browserSync.init({
  proxy: 'http://www.sitename.local/',
  host: 'www.sitename.local',
  open: 'external'
 }, function() {
                gulp.watch('style.css').on('change', function () {
            gulp.src('style.css')
            .pipe(browserSync.stream());
        });
        cb();
    });
});

gulp.task('uglify', function () {
  gulp.src('style.css')
    .pipe(uglifycss({ "max-line-len": 80 }))
    .pipe(gulp.dest('./'));
});


// Watch Files For Changes
gulp.task('watch', function() {
    gulp.watch('scss/*/*.scss', ['sass']);
    gulp.watch('scss/*.scss', ['sass']);
    gulp.watch('style.css', ['uglify'] );


});

// Default Task
gulp.task('default', ['watch',  'sass', 'uglify', 'browser-sync']);

激活gulp时,终端中会出现以下内容:

    [18:51:13] Starting 'browser-sync'...
[BS] Proxying: http://www.sitename.local
[BS] Access URLs:
 ------------------------------------------
       Local: http://localhost:3000
    External: http://www.sitename.local:3000
 ------------------------------------------
          UI: http://localhost:3001
 UI External: http://www.sitename.local:3001
 ------------------------------------------ 

虽然我在这里,但我想知道是否也可以从我网络外的计算机完全启动浏览器同步?

0 个答案:

没有答案