我來自一個咕嚕背景。建立一個Web服務器就像grunt connect
一樣簡單。使用gulp設置本地網絡服務器
我把下面的代碼在我的呼嚕聲文件並運行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');
我的形勢發生了變化,因爲我不得不遷移吞掉。但我不能讓它工作在一口吞下。可能是因爲我的背景。我正在使用gulp-webserver。並加入我的一飲而盡文件如下:
gulp.task('serve', function() {
gulp.src('app')
.pipe(webserver({
path:'dist',
port:'9090',
livereload: true,
directoryListing: true,
open: true
}));
});
當我瀏覽到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
的依賴,我目前沒有在我的辦公桌。所以我會盡快嘗試。你能解釋一下傳給src()的sources.debug是什麼,主要用於什麼功能?我在這裏有點困惑。 – Pravin
抱歉讓你困惑..'sources.debug'基本上是一個變量名..我不硬編碼路徑,將它們保存在變量中 – harishr
我不知道我做錯了什麼。它仍然顯示相同的錯誤。可能是我失去了一些東西。我會更新信息。 – Pravin