通过 Gulp 任务将变量注入 html
Inject variable into html via Gulp Task
我正在使用 Gulp 和一些插件来模板化我的 HTML 并缩小我的 HTML 即 "gulp-file-include"、"gulp-inject"、"gulp-minify-html" none 似乎提供了一种在构建时注入常量的方法,例如:
.pipe('*.html', $.gulpVar({urlpath: 'www.myurl.com'})))
然后在我的 HTML 中引用变量
联系我们
我能找到的最接近类似的东西是 gulp-ng-constant 尽管这会将它注入 JS 并使用 Angular,但我没有使用 Angular 和希望将其注入 HTML。是否有具有该功能的 gulp 插件?
你可以使用gulp-replace
gulp.task('templates', function(){
gulp.src('template.html')
.pipe(replace(/$$myvar$$/g, 'release'))
.pipe(gulp.dest('build/file.txt'));
});
以上任务正在 template.html
中用 release
替换 $$myvar$$
我正在使用 Gulp 和一些插件来模板化我的 HTML 并缩小我的 HTML 即 "gulp-file-include"、"gulp-inject"、"gulp-minify-html" none 似乎提供了一种在构建时注入常量的方法,例如:
.pipe('*.html', $.gulpVar({urlpath: 'www.myurl.com'})))
然后在我的 HTML 中引用变量
联系我们
我能找到的最接近类似的东西是 gulp-ng-constant 尽管这会将它注入 JS 并使用 Angular,但我没有使用 Angular 和希望将其注入 HTML。是否有具有该功能的 gulp 插件?
你可以使用gulp-replace
gulp.task('templates', function(){
gulp.src('template.html')
.pipe(replace(/$$myvar$$/g, 'release'))
.pipe(gulp.dest('build/file.txt'));
});
以上任务正在 template.html
release
替换 $$myvar$$