Gulp-inject变换不起作用

svf*_*fat 9 javascript gulp gulp-inject

我试图设置gulp-inject来将依赖项注入index.html.除了转换功能外,一切正常.我需要以下列方式替换部分文件路径:/frontend/src/- > /static/我尝试这样做(从某处复制粘贴):

transform : function ( filePath, file, i, length ) {
                var newPath = filePath.replace('/frontend/src', '');
                console.log('inject script = '+ newPath);
                return '<script src="/static/' + newPath  + '"></script>';
            }
Run Code Online (Sandbox Code Playgroud)

执行后,我在控制台中没有任何内容(标准gulp输出除外),并且未转换的文件路径出现在结果文件中.看起来我的自定义转换不会运行,而默认转换工作正常.

小智 6

以下对我来说即使有多个级别(/**/*.js而不是/*.js):

gulp.task('inject', function() {
    gulp.src('./test.html')
        .pipe(inject(
            gulp.src(['./Content/js/*.js'], {read: false }),
            {
                transform: function (filePath, file, i, length) {
                    var newPath = filePath.replace('/Content/js/', '');
                    console.log('inject script = '+ newPath);
                    return '<script src="/static/' + newPath  + '"></script>';
                }
            })
        )
        .pipe(gulp.dest('./'));
});
Run Code Online (Sandbox Code Playgroud)