【问题标题】:Inject variable into html via Gulp Task通过 Gulp Task 将变量注入 html
【发布时间】:2015-06-08 07:46:24
【问题描述】:

我正在使用 Gulp 和一些插件来模板化我的 HTML 并缩小我的 HTML,即“gulp-file-include”、“gulp-inject”、“gulp-minify-html”似乎都没有提供一种方法在构建时注入一个常量,例如:

.pipe('*.html', $.gulpVar({urlpath: 'www.myurl.com'})))

然后在我的 HTML 中引用变量

联系我们

我能找到的最接近类似的东西是 gulp-ng-constant 虽然这会将其注入 JS 并使用 Angular,但我没有使用 Angular 并希望将其注入 HTML。有没有具有该功能的 gulp 插件?

【问题讨论】:

    标签: gulp gulp-inject


    【解决方案1】:

    你可以使用 gulp-replace

    gulp.task('templates', function(){
      gulp.src('template.html')
        .pipe(replace(/$$myvar$$/g, 'release'))
        .pipe(gulp.dest('build/file.txt'));
    });
    

    以上任务是在template.html 中将$$myvar$$ 替换为release

    【讨论】:

    • 是的,可以完成这项工作,我也看到 gulp-preprocess 可以用来做我需要的,但我现在使用 gulp-replace
    猜你喜欢
    • 2016-01-19
    • 2019-02-10
    • 2016-06-11
    • 2016-03-13
    • 2017-10-08
    • 2020-09-26
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    相关资源
    最近更新 更多