Closed brendan8c closed 3 years ago
This is a standalone Node module, I don't think you can just use it in Gulp like that. Instead, you need to wrap it in a helper function like so:
module.exports = function updateRedirects(done) {
replaceInFile({
files: path.join(build.DEST_ASSETS, '_redirects'),
from: /%API_BASE_URL%/g,
to: config.api.baseUrl,
}, done);
};
And then use it in Gulp like with gulp.series
or gulp.parallel
This is the out of the box gulp solution Replace all lines of a similar type with others. Example: replace img/sprite.png with ../img/sprite.png
const { series } = require('gulp')
const replace = require('replace-in-file')
function updateRedirects(done) {
replace({
files: 'build/css/style.min.css',
from: /img\/sprite.png/g, // img/sprite.png – Replace this.
to: '../img/sprite.png', // ../img/sprite.png – Replace with this.
countMatches: true,
}, done)
}
exports.build = series(updateRedirects) // Start
Это автономный модуль Node, я не думаю, что вы можете просто так использовать его в Gulp. Вместо этого вам нужно обернуть его вспомогательной функцией следующим образом:
module.exports = function updateRedirects(done) { replaceInFile({ files: path.join(build.DEST_ASSETS, '_redirects'), from: /%API_BASE_URL%/g, to: config.api.baseUrl, }, done); };
А затем используйте его в Gulp, например, с помощью
gulp.series
илиgulp.parallel
Tell me can I do this with any node.js plugin? I've tried doing something similar with other node.js plugins but it didn't work. What might it depend on? What do I need to know to adopt any other node.js plugin for gulp? I am asking you because I believe you are an expert in this area.
Yes, just make your own file and import it as a plugin in your main gulpfile.
E.g.
const updateRedirects = require('./build/tasks/update-redirects');
gulp.task('build', gulp.series(
clean,
gulp.parallel(
gulp.series(
copyAssets,
updateHeaders,
updateRedirects,
createVersionFile
),
buildConfig,
buildAppJs,
buildAppCss,
buildLibJs,
),
buildIndex,
updateServiceWorker
));
I want to replace all lines
'img/sprite.png'
with on strings'../img/sprite.png'
The lines are in the file (style.min.css
) I am doing something wrong... I have errors, please help me