1

I am running the pug CLI with

pug src --out web --watch

If I have

src/
   index.pug 
   includes/
      scripts.pug
web/
  index.html (generated)

And in index.pug: include includes/scripts.pug

With this setup if I modify the scripts.pug, it generates web/includes/scripts.html that I don't need and I don't want in order to keep things clean.

Is there a way to avoit certain files / directories to compile? (for now a workaround is having the includes in html form but maybe there's a way)

Graham
  • 7,431
  • 18
  • 59
  • 84
tru7
  • 6,348
  • 5
  • 35
  • 59

2 Answers2

1

Adding an underscore prefix to files should tell Pug to not compile them directly. This is super helpful for files that are only used as includes.

So you should rename scripts.pug to _scripts.pug:

src/
  index.pug 
  includes/
    _scripts.pug
web/
  index.html (generated)

And then rewrite your include statement in index.pug to be: include includes/_scripts.pug

Sean
  • 6,873
  • 4
  • 21
  • 46
  • are you sure? I accepted the answer but didn't test until now and it seems to not work. By what I am seeing there's a specific pug-cli2 that must be installed. – tru7 Dec 17 '19 at 22:51
  • It works for the `gulp-pug` package but it may be different for other tools. – Sean Dec 18 '19 at 14:12
1

The pug-cli doesn't know about not compiling certain files. Like the previous answer mentions, it does work with gulp-pug but not pug-cli. The only way I can think of not to compile includes or extends files is to put those files in a separate root directory. For example:

src/
  templates/
        views/
            index.pug
        includes/
            scripts.pug
web/
  index.html (generated)

Then set pug to compile the views directory only.

pug -w src/templates/views/ -o web/ -P
Joel Z.
  • 543
  • 1
  • 7
  • 14