gulp 注入相对文件路径
gulp inject relative file paths
我有一个文件 testboot.js
,我想像这样注入导入语句:
import "../app/app.spec";
import "../app/navbar/navbar.spec";
请注意,导入语句是相对于 testboot.js
。 我无法找到使用 gulp 执行此操作的简洁方法。这是我的部分 gulp 任务:
gulp.task("inject", function (cb) {
gulp
.src("src/client/app/**/*.spec.js")
.pipe(debug())
.pipe(filenames("inject"))
.on("end", function () {
filenames.get("inject").map(function(e){
// do something
});
util.log("in end"); // never called
cb();
});
});
但从未调用 "end" 处理程序。谁能帮我解决这个问题?谢谢。
您正在侦听错误的事件。来自 Node.js documentation on Stream
:
The 'finish'
and 'end'
events are from the parent Writable
and Readable
classes respectively. The 'finish'
event is fired after stream.end()
is called and all chunks have been processed by stream._transform()
, 'end'
is fired after all data has been output which is after the callback in stream._flush()
has been called.
这意味着您要么必须监听 'finish'
事件:
gulp.task("inject", function (cb) {
gulp
.src("src/client/app/**/*.spec.js")
.pipe(debug())
.pipe(filenames("inject"))
.on("finish", function () {
filenames.get("inject").map(function(e){
// do something
});
util.log("in end");
cb();
});
});
或者您必须确保 stream._flush()
中的回调被调用,例如gulp.dest()
:
gulp.task("inject", function (cb) {
gulp
.src("src/client/app/**/*.spec.js")
.pipe(debug())
.pipe(filenames("inject"))
.pipe(gulp.dest('dist'))
.on("end", function () {
filenames.get("inject").map(function(e){
// do something
});
util.log("in end");
cb();
});
});
我有一个文件 testboot.js
,我想像这样注入导入语句:
import "../app/app.spec";
import "../app/navbar/navbar.spec";
请注意,导入语句是相对于 testboot.js
。 我无法找到使用 gulp 执行此操作的简洁方法。这是我的部分 gulp 任务:
gulp.task("inject", function (cb) {
gulp
.src("src/client/app/**/*.spec.js")
.pipe(debug())
.pipe(filenames("inject"))
.on("end", function () {
filenames.get("inject").map(function(e){
// do something
});
util.log("in end"); // never called
cb();
});
});
但从未调用 "end" 处理程序。谁能帮我解决这个问题?谢谢。
您正在侦听错误的事件。来自 Node.js documentation on Stream
:
The
'finish'
and'end'
events are from the parentWritable
andReadable
classes respectively. The'finish'
event is fired afterstream.end()
is called and all chunks have been processed bystream._transform()
,'end'
is fired after all data has been output which is after the callback instream._flush()
has been called.
这意味着您要么必须监听 'finish'
事件:
gulp.task("inject", function (cb) {
gulp
.src("src/client/app/**/*.spec.js")
.pipe(debug())
.pipe(filenames("inject"))
.on("finish", function () {
filenames.get("inject").map(function(e){
// do something
});
util.log("in end");
cb();
});
});
或者您必须确保 stream._flush()
中的回调被调用,例如gulp.dest()
:
gulp.task("inject", function (cb) {
gulp
.src("src/client/app/**/*.spec.js")
.pipe(debug())
.pipe(filenames("inject"))
.pipe(gulp.dest('dist'))
.on("end", function () {
filenames.get("inject").map(function(e){
// do something
});
util.log("in end");
cb();
});
});