Answer the question
In order to leave comments, you need to log in
How to write to a file using node js and gulp?
Hello. Tell me how to write data from one file to another using gulp and nodejs.
That is, I have a js file and I want to write it to a php file that needs to be created and which will be included on the page.
script.js file
export const phpReplace = done => {
const script = fs.readFileSync('public/scripts/chunk-vendors.min.js', 'utf8');
const str = '<script>\n' + script + '\n</script>';
fs.writeFile('public/includes/app_min_js.php', str);
done();
};
import {templates, phpReplace} from './script';
gulp.task(
'build',
gulp.series(templates, gulp.parallel(phpReplace ))
);
Answer the question
In order to leave comments, you need to log in
Thanks to everyone who wanted to help solve the problem.
I replaced the writeFile function with writeFileSync and it seems like the file was created with the script written.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question