node.js - gulp-inject如何解决同目录问题?

【字号: 日期:2022-09-26浏览:30作者:雯心

问题描述

愿景:

-src -tpl-tplA -index.html -index.css-tplB -index.html -index.css // Example - tplA // index.html<!-- inject:style:css --><!-- endinject --><p>这是正文</p>// index.css.test{color:red}

gulp之后变成:

-dest -tpl -tplA -index.html(injected index.css) -tplB -index.html(injected index.css) // Example - tplA// index.html.test{color:red} /*这是inject的css内容*/<p>这是正文</p>// 同理tplB、tplC、tplD...也一样遇到的问题

gulp.task(’inject’, function(){ gulp.src(’./src/**/*.html’) .pipe(inject(gulp.src(’./src/**/*.css’), { // 问题行 starttag: ’<!-- inject:style:{{ext}} -->’, transform: function(filePath, file) {return '<style>n' + file.contents.toString(’utf8’) + 'n</style>'; }})).pipe(gulp.dest(’./dest’))});

如果问题行处,src设置为具体的css路径,则可以。但是不能实现自动识别html所在的目录下,对应名字的css文件,请问有什么方法吗?

问题解答

回答1:

https://www.npmjs.com/package...

相关文章: