Javascript 吞咽任务完成,无错误,但未将任何文件保存到目标

Javascript 吞咽任务完成,无错误,但未将任何文件保存到目标,javascript,node.js,gulp,vinyl,Javascript,Node.js,Gulp,Vinyl,我被困在一个琐碎的问题中,无法掌握它 以下是场景: 我正在使用Gulp任务将我的html模板转换为javascript,使用Gulp-html2js我的环境是节点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:\Pro

我被困在一个琐碎的问题中,无法掌握它

以下是场景:

我正在使用Gulp任务将我的
html
模板转换为
javascript
,使用
Gulp-html2js
我的环境是
节点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和stackoverflow上列出的类似项目中尝试了以下建议,但没有成功

https://github.com/yeoman/generator-webapp/issues/182
https://github.com/yeoman/generator-webapp/issues/225
有人能帮我找出错误吗

谢谢

编辑所提供示例的输出:

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>

。因为管道比管道好,我给你一个我的一个gulpile的例子,你不需要把绝对机器路径放在dest中你的gulpfile是任务gulp的根路径使用js使用js路径试试这个 在使用html2js时,我不知道您的语法是否正确,但请首先尝试使用此路径

我的

 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'))
});

。因为管道比管道好,我给你一个我的一个gulpile的例子,你不需要把绝对机器路径放在dest中你的gulpfile是任务gulp的根路径使用js使用js路径试试这个 在使用html2js时,我不知道您的语法是否正确,但请首先尝试使用此路径

我的

 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'))
});

所以,我终于找到了解决办法,阿罕多利拉

问题不在于
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/'));
});

所以,我终于找到了解决办法,阿罕多利拉

问题不在于
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/'));
});

因此,我尝试了您的示例吞咽任务,
模型
运行良好,但没有文件输出。而
模板
运行时出错。我正在将输出粘贴到原始问题中的编辑。因此我尝试了您的示例吞咽任务,
模型
运行良好,但没有文件输出。而
模板
运行时出错。我正在将输出粘贴到原始问题中的编辑。