【问题标题】:gulp-html-replace not replacing entire blockgulp-html-replace 不替换整个块
【发布时间】:2016-06-15 21:29:53
【问题描述】:

我有一个 gulp 任务,它打开一个 index.html 文件并用其他内容替换两个构建/块。我正在使用“gulp-html-replace”:“^1.6.0”

其中一个块没有正确执行替换。

这是 gulp 任务

gulp.task("html:bundle", ['html:clean', 'html:copy'], function () {
    gulp.src('./src/index.html')
    .pipe(htmlReplace({
        'APPJS': '/DesktopModules/regentsigns-app/dist/app.min.js'
    }))
    .pipe(gulp.dest('dist/'));
})

这里是需要替换的html块

<!-- build:APPJS -->
<script>System.import('app').catch(function (err) { console.error(err); });</script>
<!-- endbuild -->

这是结果

<script src="/DesktopModules/regentsigns-app/dist/app.min.js"></script>

stem.import('app').catch(function (err) { console.error(err); });</script>
<!-- endbuild -->

如您所见,替换会注入新文本,但不会完全删除现有文本。

谁能帮我弄清楚这是为什么?

谢谢

【问题讨论】:

    标签: gulp gulp-html-replace


    【解决方案1】:

    如果源文件已经在目标文件夹中,这似乎发生在我身上。我会确保您没有将 index.html 文件放在捆绑任务之前的 dist 文件夹中的任务。

    【讨论】:

    • 实际上看起来是因为复制任务与捆绑任务同时运行。所以我求助于使用运行序列来确保我的副本在我的捆绑之前完成,这解决了我的问题。
    • 非常感谢,问题是文件已经存在于另一个同时执行的任务中。我清理了我的任务,将这个索引文件与我在 gulp 任务中移动的所有其他 html 隔离开来。
    猜你喜欢
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 2019-01-21
    • 2021-12-10
    相关资源
    最近更新 更多