gpt4 book ai didi

javascript - 如何使用 gulp-inject 将文件的内容插入到我的 index.html 中?

转载 作者:行者123 更新时间:2023-11-30 08:31:39 24 4
gpt4 key购买 nike

到目前为止,这是我尝试过的:

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) 时遇到了问题。我认为这与以下问题有关,但我从来没有让 mustache 为我工作:

How to avoid echoing character 65279 in php? (This question also relates to Javascript xmlhttp.responseText (ajax))

我希望有人可以给我一些建议,可以使用 gulp-injectgulp-mustache 或任何其他方式将一个文件的内容插入另一个文件。

最佳答案

使用 custom transform function注入(inject)文件的内容:

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

关于javascript - 如何使用 gulp-inject 将文件的内容插入到我的 index.html 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37060623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com