我想这样做,怎么实现?
for each file in a folder,
1) read the content,
2) wrap the content with certain strings, with the file name
(without folder, without extension) as a parameter
end-for
3) concat the result into one string
4) inject this string into a predefined row in a file
Folder structure
src/one.html
src/templates/aaa.hbs
src/templates/bbb.hbs
Content of src/one.html is a regular html,
with a certain placeholder
...
<div id="templates">
<!-- a-marker-for-string-replacement -->
</div>
...
Content of aaa.hbs
I am AA
Content of bbb.hbs
I am BB
After gulp, expected content of dist/one.html
...
<div id="templates">
<script id="aaa">
I am AA
</div>
<script id="bbb">
I am BB
</div>
</div>
...
我可以完成上述一些任务,
例如最多3个)(将结果合并为一个字符串),
然后通过通常的gulp.concat
和gulp.dest
将其输出到文件中。
我也知道该怎么做4)(将字符串注入文件中),
例如gulp-inject-string
。
但是已经花费了数小时,而且我仍然不理解gulp stream的概念:
-在文件内容前添加字符串时,如何插入当前文件的文件名?
-我可以使用gulp-concat
并将结果首先放入变量,然后结束管道,并在gulp-inject-string
中使用变量吗?