问题描述
我正在尝试在索引中注入一些文件,所有文件都连接在一起并缩小为.tmp文件夹,如下所示:
I'm trying to inject some files in my index, all of them concatenated and minified into a .tmp folder, as follows:
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'))
});
但是当我运行注入任务时,它说没有注入index.html。这是代码:
But when I run the injection task, it says "Nothing to inject into 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.
此外,仅供参考,'plugins'是一个需要我的插件的变量。
Also, just for information, 'plugins' is a variable which is requiring my plugins.
有关此问题的任何想法?
Any idea about this issue?
推荐答案
您需要在 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'))
});
否则 inject-deps
将不会等待 prep-js
在运行之前完成,这意味着连接和uglified JS文件将不在 .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.
:
- 给它一个提示告诉它什么时候完成任务,
- 并给它一个暗示,任务取决于另一个任务的完成。
这篇关于Gulp-inject说“无需注入index.html”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!