以下是我迄今尝试过的:
gulp.task('watch-index-html', function () {
gulp.watch(files, function (file) {
return gulp.src('index/index.html')
.pipe(inject(gulp.src(['index/base3.html']), {
starttag: '<!-- inject:base3:html -->'
}))
.pipe(print(function (file) {
return "Processing " + file;
}))
.pipe(gulp.dest('./'));
});
});下面是所发生的事情:
在此之前:
<body>
abcd
<!-- inject:base3:html -->
<!-- endinject -->
efgh之后:
<body>
abcd
<!-- inject:base3:html -->
<link rel="import" href="/index/base3.html">
<!-- endinject -->
efgh我希望看到的是文件的实际内容,而不是行:
<link rel="import" href="/index/base3.html">有人能告诉我,我是否可以用gulp-inject来“插入文件的内容”,或者我是否应该使用其他的东西。注意,在过去,我尝试使用gulp-mustache,但在插入字符(65279)时出现了问题。我猜想这与以下问题有关,但我从来没有办法让胡子为我工作:
如何避免在php中回显字符65279?(这个问题也与Javascript xmlhttp.responseText (Ajax)有关)
我希望有人能给我一些建议,要么用gulp-inject,要么用gulp-mustache,或者用任何其他方式将文件的内容插入到另一个文件中。
发布于 2016-05-06 07:28:09
使用自定义变换函数注入文件的内容:
gulp.task('watch-index-html', function () {
gulp.watch(files, function (file) {
return gulp.src('index/index.html')
.pipe(inject(gulp.src(['index/base3.html']), {
starttag: '<!-- inject:base3:html -->',
transform: function(filepath, file) {
return file.contents.toString();
}
}))
.pipe(print(function (file) {
return "Processing " + file;
}))
.pipe(gulp.dest('./'));
});
});https://stackoverflow.com/questions/37060623
复制相似问题