Answer the question
In order to leave comments, you need to log in
How to make transform work in gulp-inject?
Decided to try gulp, fiddling around with setting up gulp-inject to add dependencies. Everything works great, except for the transform function. I need to convert url for js files /frontend/src/
from /static/
. I tried this (copy-pasted from somewhere):
transform : function ( filePath, file, i, length ) {
var newPath = filePath.replace('/frontend/src', '');
console.log('inject script = '+ newPath);
return '<script src="/static/' + newPath + '"></script>';
}
Answer the question
In order to leave comments, you need to log in
If you carefully read the doc, then the following syntax is written there
var sources = gulp.src('Какой-то путь',{read: false}),
param = {
transform: function (filepath) {
if (filepath.slice(-3) === '.js') {
var newPath = filepath.slice(6); // Что нужно обрезать
return '<script src="' + newPath + '"></script>';
}else{
// Use the default transform as fallback:
return inject.transform.apply(inject.transform, arguments);
}
}
};
gulp.src('Куда мы вставим наши файлы')
.pipe(plumber()) // обработка ошибок
.pipe(wiredep()) // bower файлы туда же суем
.pipe(inject(sources, params)) // вставить свои файлы
.pipe(gulp.dest('Куда это все сохранить'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question