Reputation: 37
I have a gulpfile that processes both HTML and PHP files using a template manager (Nunjucks) which works fine but I think the process could be improved.
Currently I am using one task to process the HTML files and another one to process the PHP files. The tasks and templates are exactly the same except for different gulp.src globs to target just the HTML or just the PHP files and an additional .pipe(rename({extname: '.php'}))
in the PHP task because Nunjucks outputs all files as .html
no matter what the input extension is, which, to be honest, I cannot see why that is necessary.
The simple solution to reduce my tasks to just one would be to tell Nunjucks not to change the file extensions of source files but I have not found a configuration flag for that in their documentation.
My initial thoughts are to use the built-in Node Path module to check what the extension is before the Nunjucks process, that sets a flag to true if it is .php
. Then, after the Nunjucks process, use gulp-if to check the flag and if true, rename back to .php
.
As I am new to Gulp and after extensive searching, have not found any help to get me started, I'm hoping that the community can help me out with a solution and my Gulp learning curve.
Upvotes: 0
Views: 373
Reputation: 37
I did not look hard enough. Now I can process both HTML and PHP using one task. There is an option to ignore the default .html
extension.
For anyone else out there:
.pipe(nunjucksRender({
path: ['src/views'],
inheritExtension: true
}))
Upvotes: 1