我有这样的公共资源:
public/
xyz/
index.html
js/
a.js
b.js
css/
a.css
b.css
我想用来gulp-useref
构建html,我改成index.html
这个:
<!-- build:css /xyz/css/index.css -->
<link href="/xyz/css/a.css" rel="stylesheet" />
<link href="/xyz/css/b.css" rel="stylesheet" />
<!-- endbuild -->
<!-- build:js /xyz/js/index.js -->
<link href="/xyz/js/a.js" rel="stylesheet" />
<link href="/xyz/js/b.js" rel="stylesheet" />
<!-- endbuild -->
我这样写 gulp:
gulp.task("html", async function() {
gulp.src("public/xyz/*.html")
.pipe(useref())
.pipe(gulpif("*.js", uglify()))
.pipe(gulpif("*.css", cssMin()))
.pipe(gulp.dest("dist/public/xyz"))
})
第一个问题是:useref 找不到absolute path: /xyz/js/a.js
.
然后我尝试将 html 模板更改为:
<!-- build:css /xyz/css/index.css -->
<link href="css/a.css" rel="stylesheet" />
<link href="css/b.css" rel="stylesheet" />
<!-- endbuild -->
<!-- build:js /xyz/js/index.js -->
<link href="js/a.js" rel="stylesheet" />
<link href="js/b.js" rel="stylesheet" />
<!-- endbuild -->
它运行正常,然后出现第二个问题,useref产生冗余xyz
目录:
dist/
public/
xyz/
index.html
xyz/
js/
a.js
b.js
css/
a.css
b.css