Gulp: 从页脚读取脚本标签
Gulp: Read script tags from footer
我正在尝试使用 Gulp 完成以下操作:
- 读取文件
footer.html
并解析 <script src="
标签中的所有路径 - 使用 gulp-dom-src
;
- 将这些路径传送到
contact
;
uglify
一切;
最后的步骤很简单,但我坚持第一步。我当前的代码是:
var domSrc = require("gulp-dom-src"),
concat = require("gulp-concat"),
uglify = require("gulp-uglify");
var footerFile = "Footer/View-en.html";
gulp.task("deploy", function(){
domSrc({ file: footerFile, selector: "script", attribute: "src" })
.pipe(concat("script.min.js"))
.pipe(uglify())
.pipe(gulp.dest("Dist/Resources/"))
});
如果我尝试使用 .pipe(debug({title: "pipe:"}));
调试管道,它似乎是空的,有什么原因吗?还有其他推荐的软件包来完成同样的任务吗?
谢谢。
我有同样的问题,这让我大吃一惊))
所以有答案:你需要在 domSrc
选项中添加 cwd:process.cwd()
,像这样:
var options = {
cwd: process.cwd(),
file: footerFile,
selector: "script",
attribute: "src"
};
domSrc(options);
我正在尝试使用 Gulp 完成以下操作:
- 读取文件
footer.html
并解析<script src="
标签中的所有路径 - 使用gulp-dom-src
; - 将这些路径传送到
contact
; uglify
一切;
最后的步骤很简单,但我坚持第一步。我当前的代码是:
var domSrc = require("gulp-dom-src"),
concat = require("gulp-concat"),
uglify = require("gulp-uglify");
var footerFile = "Footer/View-en.html";
gulp.task("deploy", function(){
domSrc({ file: footerFile, selector: "script", attribute: "src" })
.pipe(concat("script.min.js"))
.pipe(uglify())
.pipe(gulp.dest("Dist/Resources/"))
});
如果我尝试使用 .pipe(debug({title: "pipe:"}));
调试管道,它似乎是空的,有什么原因吗?还有其他推荐的软件包来完成同样的任务吗?
谢谢。
我有同样的问题,这让我大吃一惊))
所以有答案:你需要在 domSrc
选项中添加 cwd:process.cwd()
,像这样:
var options = {
cwd: process.cwd(),
file: footerFile,
selector: "script",
attribute: "src"
};
domSrc(options);