也许有人可以指出我的解决方案。
我有包含多个脚本标记的HTML文件。我需要
我尝试使用gulp-useref并且它完成了我需要的一切,但它不允许动态更改替换脚本名称(必须在html注释中说明)
另一个插件gulp-html-replace完全涵盖了我的替换需求,但根本没有管道引用的脚本。
解决此类任务的常用方法是什么?因为它似乎并不奇怪。提前谢谢。
答案 0 :(得分:0)
最后决定同时使用它们。
HTML:
<!-- build:js_replace -->
<!-- build:js INTERMEDIATE.js -->
<script type="text/javascript" src="scripts/script1.js"></script>
<script type="text/javascript" src="scripts/script2.js"></script>
<!-- endbuild -->
<!-- endbuild -->
在gulpfile.js中:
gulp.src(dirName + '/*.html')
.pipe(useref({}))
.pipe(gif("**/*.js", rename(function (filePath) {
filePath.basename = "someotherfilename";
})))
// ... Upload to cloud storage
.pipe(gif("**/*.html", htmlreplace({
js_replace: CLOUD_STORAGE_URL + "/scripts/someotherfilename.js"
})))
.pipe(gif("**/*.html", gulp.dest("./build/")));