How i can setting the home directory for Pug in Gulp

206 Views Asked by At

I am trying to set home directory for Pug to Galp using this code:

function renderPug() {
  return src('app/pug/pages/**/*.pug')
    .pipe(pug({
      pretty: true,
      basedir: __dirname,
    }))
    .pipe(dest('build'))
    .on('end', browserSync.reload);
}

But when doing the task, I get this error:

    ENOENT: no such file or directory, open '/Users/Boboshko/boboshko-me/app/pug/pages/photos/russia/moscow/2019/layout/templates/photos-inside.pug'
    at /Users/Boboshko/boboshko-me/app/pug/pages/photos/russia/moscow/2019/photos.pug line 1
Details:
    errno: -2
    syscall: open
    code: ENOENT
    path: /Users/Boboshko/boboshko-me/app/pug/pages/photos/russia/moscow/2019/layout/templates/photos-inside.pug
    domainEmitter: [object Object]
    domainThrown: false

What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

This works for me:

const path = require('path');

function renderPug() {
  return src('app/pug/pages/**/*.pug')
    .pipe(pug({
      pretty: true,
      basedir: path.join(__dirname, 'app', 'pug'),
    }))
    .pipe(dest('./build'))
    .on('end', browserSync.reload);
}

And the path to the file must be specified relative to the root folder: /layout/templates/photos-inside.