2017-04-04 160 views
1

我正在使用gulp.The任務正在運行創建所需的文件夾。但是我在瀏覽器中運行時得不到GET /錯誤。我附上了我的項目結構的圖像以及命令行command line output中的輸出。 Project Structure。我的index.html包含以下不能上http:// localhost:3000/

<!DOCTYPE html> 
<html lang="en" ng-app="helloWorldApp"> 
    <head> 
     <title>Angular hello world app</title> 
     <link href="css/main.css" rel="stylesheet"> 
    </head> 
    <body> 
     <ng-view class="view"></ng-view> 
    </body> 
    <script src="js/scripts.js"></script> 
</html> 

我想知道爲什麼它不能獲取或不正確的路由和應該做什麼。所以,問題是當服務器在本地主機上運行和我打本地主機:3000 /瀏覽器,它說不能用白色background.Following得到的是我的gulpfile.js

const gulp = require('gulp'); 
const concat = require('gulp-concat'); 
const browserSync = require('browser-sync').create(); 

const scripts = require('./scripts'); 
const styles = require('./styles'); 

var devMode = false; 



gulp.task('css',function(){ 
    gulp.src(styles) 
     .pipe(concat('main.css')) 
     .pipe(gulp.dest('./dist/css')) 
     .pipe(browserSync.reload({ 
      stream : true 
    })) 
}); 

gulp.task('js',function(){ 
    gulp.src(scripts) 
     .pipe(concat('scripts.js')) 
     .pipe(gulp.dest('./dist/js')) 
     .pipe(browserSync.reload({ 
      stream : true 
    })) 
}); 

gulp.task('html',function(){ 
    gulp.src('./templates/**/*.html') 
     .pipe(gulp.dest('./dist/html')) 
     .pipe(browserSync.reload({ 
      stream : true 
    })) 
}); 

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

    gulp.start(['css','js','html']); 
    console.log("finshed build"); 
}); 

gulp.task('browser-sync',function(){ 
    browserSync.init(null,{ 
     open : false, 
     server : { 
      baseDir : 'dist' 
     } 
    }); 
    console.log("finshed browser "); 
}); 

gulp.task('start',function(){ 
    devMode = true; 
    gulp.start(['build','browser-sync']); 
    gulp.watch(['./css/**/*.css'],['css']); 
    gulp.watch(['./js/**/*.js'],['js']); 
    gulp.watch(['./templates/**/*.html'],['html']); 
}); 
+0

我很抱歉,但您的問題不夠清楚,我們無法理解您的問題是什麼!你的錯誤是什麼?它是什麼時候發生的?你期望發生什麼? – Hampus

+0

爲什麼您將null作爲第一個參數傳遞給瀏覽器同步以及什麼是open:false應該這樣做? – Hampus

+0

open:false是爲了避免在沒有請求的情況下直接打開選項卡。並且不需要null。 – FalconFlyer

回答

1

您需要將browserSyncdist/html/index.html文件作爲起始頁面index

gulp.task('browser-sync',function(){ 
    browserSync.init(null,{ 
     open : false, 
     server : { 
      baseDir : 'dist', 
      index : "html/index.html" 
     } 
    }); 
    console.log("finshed browser "); 
}); 
+0

我累了它沒有工作! :( – FalconFlyer

+0

你是否在正確的目錄中?如果你啓用目錄列表,請指定'http:// localhost:3000'?'用'directory:true'替換'index:「html/index.html」'' – lofihelsinki

相關問題