2016-11-08 4 views
1

私は一種の問題に悩まされています。ここGulpタスクはエラーなしで完了しますが、宛先にファイルが保存されていません

はシナリオです:

私はgulp-html2js私の環境を使用してjavascriptに私のhtmlテンプレートを変換するがぶ飲みタスクを使用していますここ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')); 
}); 

iは、タスクを実行すると数分で完了しますが、templates.jsbinディレクトリに生成されません

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 

私は

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

は、誰かが私の間違いを見つけるために助けることができ、同様のGitHubの上でリストされている項目とstackoverflowの中の提案の下に試みたが成功していません。

ありがとうございました。提供される実施例の

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

。パイプの前にパイプが良いです、私はあなたの私のgulpileの例を与えると、絶対マシンのパスをdestに置く必要はありませんgulpfileは、仕事のルートパスですjs jsパスを使用して作業する Inever use 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

私はgulpタスクの例を試しました。 'models'はうまく動作しますが、ファイル出力はありません。 'templates'はエラーで実行されます。私は元の質問の編集に出力を貼り付けています。 – shoaibhb

関連する問題