2016-04-28 42 views
2

我有一個問題,讓grunt-serve任務的本地服務器的行爲應該像普通服務器一樣。我grunt.initConfig對象就像如下:grunt-serve不爲'index.html'提供'/'請求

grunt.initConfig({ 
    'serve': { 
     'path': '/Users/honkdonky/Desktop/testspace/angular', 
     }, 
     'options': { 
     'port': '9999' 
     } 
    } 
    }); 

但是當我要求這個鏈接:

http://localhost:9999/

的index.html有不會被渲染。相反,我所看到的是可用文件的列表。該項目應該通過呈現index.html和路由配置在angularjs模塊中來將請求路由到「/」。其配置如下:

phoneApp.config(['$routeProvider', 
    function($routeProvider) { 
     $routeProvider. 
      when('/phones', { 
       templateUrl: 'phone-list.html', 
       controller: 'PhoneListCtrl' 
      }). 
      when('/phones/:phoneId', { 
       templateUrl: 'phone-detail.html', 
       controller: 'PhoneDetailCtrl' 
      }). 
      otherwise({ 
       redirectTo: '/phones' 
      }); 
    } 
]); 

回答

0

我不知道這是否有幫助。但我建議你可以嘗試使用gulp-webserver。它使用起來非常容易,並且具有很酷的功能,例如livereload(當文件夾中有任何更改時,會自動刷新瀏覽器)。

+1

將gulp添加到工具列表中並不是一個好選擇,但您的主要想法是正確的; grunt-serve並不是作爲服務器的最佳選擇。 –