Answer the question
In order to leave comments, you need to log in
File generation in gulp. Automating build processes?
To automate processes, I want to introduce automatic creation of the necessary files into the assembly [gulp + webpack (only js)].
What you need: in the pages folder are *.pug || *.html files of layout pages. When adding any file to this folder, it is necessary to make the automatic creation of the file in another controllers folder approx. pagename.controller.js In which the template code will already lie.
Structure example:
pages
- about.pug
controllers
- about.controller.js
After adding the store.pug file to the pages folder.
pages
- about.pug
- store.pug
controllers
- about.controller.js
- store.controller.js - automatically generated file with pre-existing template code.
Question.
1. In which direction to dig, in terms of ready-made solutions, materials.
2. If you use a regular plugin to create files using gulp, how is the logic of automatic substitution of imports in the necessary files carried out? Or is it necessary to hang a gulp listener on a new file?
Answer the question
In order to leave comments, you need to log in
Google this way
const gulp = require('gulp');
const fs = require('fs');
const path = require('path');
const watcher = gulp.watch('./pages', { events: ['add'] });
watcher.on('add', function(p, stats) {
const name = path.basename(p, path.extname(p));
fs.writeFileSync(`./controllers/${name}.controller.js`, 'то, что будет в файле');
});
php artisan make:controller PhotoController
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question