Gulp packing problem

this project uses the gulp-replace plug-in to implement the include function (introducing public header.html, footer.html, etc.). There was no problem with the project before, but later, as the project grew larger, the problem of path and packaging time was exposed, the first packaging can be achieved, but the second packaging path will have problems, and the packaging time will become long. The function implementation code is as follows:

// include 
function includeFn () {
    return gulpReplace(/\<include.*<\/include>/g, function (a, b) {
        var regSrc = /(src[ ]*=[ ]*[""]([^"]*)[""])/g,
            result = regSrc.exec(a),
            fileCon, src, srcReal;
        if ( !result) {
            return a;
        }
        src = result[2].trim();
        srcReal = path.resolve(path.parse($.streamFilePath).dir, src);
        if (!$[srcReal]) {
            try {
                $[srcReal] = fs.readFileSync(srcReal).toString();
            } catch (err) {
                console.log(chalk.bgRed(":") + "" + $.streamFilePath);
                console.log(err);
            }
        }
        fileCon = $[srcReal];
        // // 
        // var regOn = /(on[]*=[]*[""]([\d]+)[""])/g,
        //     onResult = regOn.exec(a),
        //     num;
        // if ( onResult ) {
        //     num = parseInt(onResult[1], 10);
        // }

        return fileCon;
    });
}

// htmlinclude,include
gulp.task("dev-html",  function () {
    return gulp.src(["src/**/*.html", "!src/**/include/*.html","!src/common/**/*.html"]).
    // 
        pipe(gulpChanged(EVN_PRO)).
        // 
        pipe(mapStream(function (file, cb) {
            $.streamFilePath = file.history[0];
            cb(null, file);
        })).
        pipe(gulpDebug({title: chalk.bgBlue("---HTML: ")})).
        pipe(includeFn()).
        pipe(gulpAbsolute({dev: "src"})).
        pipe(gulp.dest(EVN_PRO)).
        pipe(browserSync.stream());
});

the project path is as follows:
clipboard.png
I hope the bosses can take a look at it and give some suggestions and ideas. Thank you!

Apr.07,2022

what is the wrong way


feels gulp-replace more emphasis on text substitution, if you want include public part, use gulp-file-include .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36c04-2c030.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36c04-2c030.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?