node.js - gulp-inject如何解决同目录问题?
大家讲道理
大家讲道理 2017-04-17 15:43:49
[Node.js讨论组]

愿景:

-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)
ringa_lee

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号