2016-11-08 40 views
1

我陷入了一種微不足道的問題,無法得到它的一個竅門。吞噬任務完成,沒有錯誤,但沒有文件保存到目的地

這裏的情景:

我使用咕嘟咕嘟任務我html模板轉換爲javascript使用gulp-html2js我的環境是Node v6.9.1, gulp 3.9.1, Windows 7

這裏是gulpfile.js

var gulp = require('gulp'); 
var concat = require('gulp-concat'); 
var html2js = require('gulp-html2js'); 
var sourceDir = "D:\Programs_Insalled\nodejs\nodeapps\myApp" 

gulp.task('templates', function() { 
    return gulp.src('D:\Programs_Insalled\nodejs\nodeapps\myApp\templates\*.html'). 
    pipe(html2js({outputModuleName: 'templates'})). 
    pipe(concat('templates.js')). 
    pipe(gulp.dest('D:\Programs_Insalled\nodejs\nodeapps\myApp\bin')); 
}); 

當我運行任務,它完成後,在幾米 - 秒但templates.js不生成在bin目錄

D:\Programs_Insalled\nodejs\nodeapps\myApp>gulp templates 
[15:28:45] Using gulpfile D:\Programs_Insalled\nodejs\nodeapps\myApp\gulpfile.js 
[15:28:45] Starting 'templates'... 
[15:28:45] Finished 'templates' after 19 ms 

我曾嘗試下面GitHub上和計算器列出類似的項目建議,但都沒有成功,

https://github.com/yeoman/generator-webapp/issues/182 
https://github.com/yeoman/generator-webapp/issues/225 

有人能幫忙找到我的錯誤。

謝謝。

EDIT輸出的設置的例子:

D:\Programs_Insalled\nodejs\nodeapps\myApp>gulp models 
[17:13:10] Using gulpfile D:\Programs_Insalled\nodejs\nodeapps\myApp\gulpfile.js 
[17:13:10] Starting 'models'... 
[17:13:10] Finished 'models' after 21 ms 

D:\Programs_Insalled\nodejs\nodeapps\myApp>gulp templates 
[17:13:13] Using gulpfile D:\Programs_Insalled\nodejs\nodeapps\myApp\gulpfile.js 
[17:13:13] Starting 'templates'... 
D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules\vinyl\index.js:120 
    if (!this.path) throw new Error('No path specified! Can not get relative.'); 
        ^

Error: No path specified! Can not get relative. 
    at File.get (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules\vinyl\index.js:120:27) 
    at DestroyableTransform.bufferContents [as _transform] (D:\Programs_Insalled\nodejs\nodeapps\myA 
pp\node_modules\gulp-concat\index.js:70:20) 
    at DestroyableTransform.Transform._read (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules 
\gulp-concat\node_modules\readable-stream\lib\_stream_transform.js:184:10) 
    at DestroyableTransform.Transform._write (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_module 
s\gulp-concat\node_modules\readable-stream\lib\_stream_transform.js:172:12) 
    at doWrite (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules\gulp-concat\node_modules\rea 
dable-stream\lib\_stream_writable.js:237:10) 
    at writeOrBuffer (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules\gulp-concat\node_modul 
es\readable-stream\lib\_stream_writable.js:227:5) 
    at DestroyableTransform.Writable.write (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules\ 
gulp-concat\node_modules\readable-stream\lib\_stream_writable.js:194:11) 
    at DestroyableTransform.ondata (D:\Programs_Insalled\nodejs\nodeapps\myApp\node_modules\through2 
\node_modules\readable-stream\lib\_stream_readable.js:531:20) 
    at emitOne (events.js:96:13) 
    at DestroyableTransform.emit (events.js:188:7) 

D:\Programs_Insalled\nodejs\nodeapps\myApp> 

回答

0

所以,我終於摸索出瞭解決方案,Alhamdolilah

問題是不與gulp task,或html2js,真正的問題是與gulp-concat

,我已經意識到,提高代碼不需要它作爲輸出已經被html2js

這裏連接起來:

gulp.task('templates', function() { 
    gulp.src('templates/*.html') 
     .pipe(html2js('templates.js', { 
      outputModuleName: 'templates', 
      name: 'templates' 
     })) 
     .pipe(gulp.dest('bin/')); 
}); 
0

。對於pipe來說更好的是在pipe之前,我給你一個例如我的一個gulpile,並且你不需要在dest中放置絕對機器路徑你的gulpfile是一個任務吞噬工作的根路徑使用js路徑試試這個 Inever使用html2js I不知道如果你的語法是正確的,但第一次嘗試這個路徑

我如

gulp.task('models', function(){ 
     return gulp.src('models/*.*') 
     .pipe(gulp.dest('../dist/models')) 
    }); 

嘗試爲您

gulp.task('templates', function() { 
    return gulp.src('templates/*.html') 
    .pipe(html2js({outputModuleName: 'templates'})) 
    .pipe(concat('templates.js')) 
    .pipe(gulp.dest('bin')) 
}); 
+0

所以我試着你的例子吞噬任務,'模型'運行良好,但沒有文件輸出。而'templates'運行時出錯。我正在將輸出粘貼到原始問題的編輯中。 – shoaibhb

相關問題