我正在使用gulp-inject向位于dist/index.html
和dist/css/*.css
dist/js/*.js
注入一些css和js文件
gulp.task('prep-index', function () {
var target = gulp.src('./dist/index.html');
var sources = gulp.src(['./dist/js/*.js', './dist/css/*.css'], {read: false}, {relative: true});
return target.pipe(inject(sources))
.pipe(gulp.dest('./dist/'));
});
目前它是从项目的基本URL注入文件,但我希望它从目标文件中注入文件链接,即dist/index.html
从/dist/css/*.css
到css/*.css
从/dist/js/*.js
到js/*.js
但它的产生是这样的:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Directi Task</title>
<!-- inject:css -->
<link rel="stylesheet" href="/dist/css/basscss.min.css">
<link rel="stylesheet" href="/dist/css/style.css">
<!-- endinject -->
</head>
<body>
<!-- inject:js -->
<script src="/dist/js/jquery.min.js"></script>
<script src="/dist/js/script.min.js"></script>
<!-- endinject -->
</body>
</html>
有关此的任何提示吗?
答案 0 :(得分:0)
发现错误,{relative: true}
应在inject()
内,但不在src()
return target.pipe(inject(sources, {relative: true}))
解决了这个问题。