【问题标题】:gulp-connect and gulp-open file not load through the servergulp-connect 和 gulp-open 文件不通过服务器加载
【发布时间】:2015-09-09 23:22:49
【问题描述】:

我正在尝试运行 Web 服务器并通过 gulp-connect 和 gulp-open 打开 HTML 文件。

服务器正在运行,html 已正确打开,但不是通过服务器打开,而是作为 HDD 中的文件。

在 URL 地址栏上我可以看到:“file:///Users/....”而不是“http://localhost:9000/

有谁知道可能是什么问题?

感谢您的帮助

"use strict";

var gulp = require('gulp');
var gulpConnect = require('gulp-connect'); // run a local dev server
var gulpOpen = require('gulp-open'); // open a URL in the browser

var config ={
    port:'9000',
    baseDevUrl:'http://localhost',
    paths: {
        html: './src/*.html',
        dist:'./dist'
    }

};
// start a local development server

gulp.task('connect',function(){

    gulpConnect.server({
        root:['dist'],
        port: config.port,
        base: config.baseDevUrl,
        livereload:true
    });

});

gulp.task('open',['connect'],function(){
       gulp.src('dist/index.html')
           .pipe(gulpOpen('',{ url: config.baseDevUrl +':'+ config.port +'/', app:'google chrome'}));
});

gulp.task('html',function(){
    gulp.src(config.paths.html)
        .pipe(gulp.dest(config.paths.dist))
        .pipe(gulpConnect.reload());
});

gulp.task('watch',function(){

    gulp.watch(config.paths.html,['html']);


});


gulp.task('default',['html','open','watch']); 

【问题讨论】:

    标签: gulp-connect


    【解决方案1】:

    好的,这是你打开东西的方式:

      gulp.src('./index.html').pipe(gulpOpen({uri: 'http://localhost:8888', app: 'Google Chrome'}));
    

    gulpOpen 中有一个额外的第一个参数,url 应该是 uri

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多