What's the most efficient way to read, rebuild

2019-07-04 01:21发布

I'm creating a system that can read through any file (php, jsp, html, etc), locate block tags, and do a replacement based on the information in the block tag.

Code I would write into my file:

<!-- build:<name> -->
    {
        "testObject": {
             "name": "jonathan",
             "number": 3,
             "male": true
         }
    }
<!-- endBuild -->

Desired replacement:

<h1>Jonathan</h1>
<p>is a male and is positioned at #3.</p>

As you may notice, I've used components of gulp-html-replace. I've researched gulp-data and know how to use gulp.src and gulp.dest to build out files. Just missing the read, build, and replace the object step. Ideally this will work on multiple object instances throughout the document. Thanks.

1条回答
干净又极端
2楼-- · 2019-07-04 01:52

Because Gulp uses a pipe system and all the files become streams, you can write your own pipe/plug-in to process files in very specific ways. Check out Gulp Writing Plugins, section Modifying file content.

Notable Mention

gulp-replace might actually do the trick

查看更多
登录 后发表回答