使用gulp设置本地Web服务器

Pra*_*vin 4 webserver gulp

我来自笨拙的背景.设置Web服务器就像这样简单grunt connect.

我会将以下代码放在我的grunt文件中并运行grunt connect:

grunt.initConfig({
        // fire up the local server
        connect: {
            server: {
                options: {
                    port: 9778, //port to host on
                    livereload: 35729,
                    hostname: '0.0.0.0', //the hostname
                    base: 'out/' //the relative path from grunt file to base folder of web app
                }
            }
        }
    });

grunt.loadNpmTasks('grunt-contrib-connect');
Run Code Online (Sandbox Code Playgroud)

我的情况发生了变化,因为我不得不迁移到gulp.但我不能让它干涸.可能是因为我的背景.我正在使用gulp-webserver.并添加了我的gulp文件如下:

gulp.task('serve', function() {
  gulp.src('app')
    .pipe(webserver({
      path:'dist',
      port:'9090',
      livereload: true,
      directoryListing: true,
      open: true
    }));
});
Run Code Online (Sandbox Code Playgroud)

当我导航到时localhost:9090,我收到了回复:cannot GET /

我究竟做错了什么?不是gulp文件的路径相对路径?我应该传递给gulp.src谁?如果有人能给我一个关于哪里看的话,这将是一个很大的帮助.

编辑1 我的gulpfile,src文件夹和构建后的文件夹,即dist文件夹都在同一级别.

??? src       // my raw application folder
??? dist      // application folder after building
|   .
|   .
|   ??? index.html
??? gulpfile.js
Run Code Online (Sandbox Code Playgroud)

har*_*shr 13

主要是它意味着它没有找到index.html

return gulp.src('./app/')
  .pipe(plugin.webserver({
      host: '0.0.0.0',
      port: 6639,
      livereload: true,
      open: true,
      fallback: './dist/index.html'
  }));
Run Code Online (Sandbox Code Playgroud)

主要是路径设置的问题..在下面的情况下尝试

  gulp.src('dist')
    .pipe(webserver({
         ......
    }));
Run Code Online (Sandbox Code Playgroud)