sindresorhus / gulp-nunjucks

Precompile Nunjucks templates
MIT License
152 stars 20 forks source link

Possible to specify extension for output? #30

Closed jwhazel closed 6 years ago

jwhazel commented 6 years ago

I like to use the .njk extension to specify a template file. This plugin seems to pass that extension through as the output name. Is there a way to force it to output as .html without using other plugins?

If not maybe a good feature enhancement as I can't think of a scenario where one would want to output something besides an .html file.

dmoosocool commented 6 years ago

i got same problem,

import template from 'gulp-nunjucks';
import rename from 'gulp-rename';
gulp.src(['./src/**/*.njk'],{ base: CONFIG.path.src})
       .pipe(template.compile())
       .pipe(rename({
          extname: '.html'
       }))
       .pipe(gulp.dest(CONFIG.path.publish));

then i add gulp-rename, is works for me, hope to help u.

sindresorhus commented 6 years ago

This plugin now requires Gulp 4, where automatic renaming works fine. If you're stuck on Gulp 3, you can use the above solution.

alkorlos commented 3 years ago

Good day. What did you mean by "...Gulp 4, where automatic renaming works fine"? I have code with gulp 4 and gulp-nunjucks:

const gulp = require('gulp');

const nunjucks = require('gulp-nunjucks');

const templates = function() {
    return gulp.src('src/templates/**/*.njk')
        .pipe(
            nunjucks.compile()
        )
        .pipe(gulp.dest('build'));
}

const start = gulp.series(
    templates
);

exports.start = start;

Need compiling to .html, but input and output files extension is .njk. Some options are missing or should this code compile to .html and it does not work for me correctly?

Cheers.

sindresorhus commented 3 years ago

Turns out I only did the extension change in .precompile(), but not in .compile(). This is fixed now.

https://github.com/sindresorhus/gulp-nunjucks/releases/tag/v5.0.2

alkorlos commented 3 years ago

Thank you a lot!

onebitrocket commented 2 years ago

Is there away to prevent automatically renaming file extensions to .html ?

I used gulp-nunjucks in a gulp 3 pipeline to process some static data in php and htaccess files.

In a gulp 4 build I cannot seem stop these file extensions being renamed

Thanks