简体   繁体   English

Gulp-inject说“没有什么可以注入index.html”

[英]Gulp-inject says “Nothing to inject into index.html”

I'm trying to inject some files in my index, all of them concatenated and minified into a .tmp folder, as follows: 我正在尝试在索引中注入一些文件,所有文件都连接在一起并缩小为.tmp文件夹,如下所示:

gulp.task('prep-js',['clean'], function(){
  var jspath = './src/page/**/*.js';
  var treatJs = gulp.src(jspath)
         .pipe(plugins.concat('scripts.js'))
         .pipe(plugins.uglify())
         .pipe(gulp.dest('.tmp/page/js'))
});

But when I run the injection task, it says "Nothing to inject into index.html". 但是当我运行注入任务时,它说“没有注入index.html”。 Here's the code: 这是代码:

gulp.task('inject-deps', ['prep-css', 'prep-js'], function(){

  //select main bower files
  var bowerDep = gulp.src(plugins.mainBowerFiles(), {read: false});

  //inject files
  return  gulp.src('./src/page/index.html')
          .pipe(plugins.inject(bowerDep, {relative: true, name:'bower'}))
          .pipe(plugins.inject(gulp.src('.tmp/page/js/*.js'), {name:'frontjs'}))
          .pipe(plugins.inject(gulp.src('.tmp/page/css/*.css'), {name:'frontcss'}))
          .pipe(gulp.dest('.tmp/page'));
});

Interesting thing, the first pipe injecting the main bower files works perfectly, but it doesn't happen to the following two. 有趣的是,注入主要凉亭文件的第一个管道工作完美,但它不会发生在以下两个。

Also, just for information, 'plugins' is a variable which is requiring my plugins. 另外,仅仅是为了获取信息,'plugins'是一个需要我的插件的变量。

Any idea about this issue? 对这个问题有什么看法吗?

You need to return the stream in your prep-js task: 您需要在prep-js任务中返回流:

gulp.task('prep-js',['clean'], function(){
  var jspath = './src/page/**/*.js';
  return gulp.src(jspath)
         .pipe(plugins.concat('scripts.js'))
         .pipe(plugins.uglify())
         .pipe(gulp.dest('.tmp/page/js'))
});

Otherwise inject-deps will not wait for prep-js to finish before it runs, meaning the concatenated and uglified JS files will not be in .tmp/page/js yet. 否则, inject-deps将不会等待prep-js在它运行之前完成,这意味着连接和uglified JS文件将不会在.tmp/page/js

Relevant portion of the Gulp documentation : Gulp文档的相关部分:

Note: By default, tasks run with maximum concurrency -- eg it launches all the tasks at once and waits for nothing. 注意:默认情况下,任务以最大并发性运行 - 例如,它立即启动所有任务并且不等待任何操作。 If you want to create a series where tasks run in a particular order, you need to do two things: 如果要创建一个按特定顺序运行任务的系列,则需要执行以下两项操作:

  • give it a hint to tell it when the task is done, 在任务完成时给它一个暗示告诉它,
  • and give it a hint that a task depends on completion of another. 并给它一个暗示,任务取决于另一个任务的完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM