我尝试设置 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>';
}
执行后,我在控制台中什么都没有(除了标准的 gulp 输出),并且未转换的文件路径出现在结果文件中。看起来我的自定义转换没有运行,而是使用默认转换。