Erik Gillespie
Erik Gillespie

Reputation: 3959

Excluding a directory from Jekyll watch

I'm using Jekyll 3.1.1 to generate a blog and I recently introduced a Git hook to automatically publish changes pre-push.

After introducing this hook, I have started getting the following error when I run jekyll serve:

Configuration file: /Users/egillespie/Projects/blog.givingjar.org/_config.yml
            Source: /Users/egillespie/Projects/blog.givingjar.org
       Destination: /Users/egillespie/Projects/blog.givingjar.org/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.223 seconds.
        ** ERROR: directory is already being watched! **

        Directory: /Users/egillespie/Projects/blog.givingjar.org/node_modules/git-scripts/bin/hooks

        is already being watched through: /Users/egillespie/Projects/blog.givingjar.org/node_modules/git-scripts/bin/hooks

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
 Auto-regeneration: enabled for '/Users/egillespie/Projects/blog.givingjar.org'
Configuration file: /Users/egillespie/Projects/blog.givingjar.org/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

What's peculiar is that I am excluding node_modules in _config.yml:

exclude:
  - Gemfile
  - Gemfile.lock
  - LICENSE
  - README.md
  - package.json
  - Gruntfile.js
  - node_modules

node_modules is correctly being excluded from building (i.e. there is no node_modules subdirectory in _site).

I'm also excluding node_modules in .gitignore:

# project
node_modules
_site*
.sass-cache
.jekyll-metadata

# general
.DS_Store
Thumbs.db
ehthumbs.db

Based on this GitHub issue and this commit it seems like node_modules should be excluded from the watch, but it's not. I can't decipher from the documentation if there's another way to exclude files from the watch.

What is the proper way for me to exclude a directory from the watch and avoid the error described above?

Upvotes: 13

Views: 5256

Answers (3)

cmaceachern
cmaceachern

Reputation: 429

Judging by the paths displayed in your output, you're on macOS. The jekyll-watch gem is responsible for this area (watch/rebuild features), which itself depends on the 'listen' gem. The listen gem itself uses the rb-inotify gem as a dependency, which has several issues with macOS specifically and its filesystem. This results in several bugs in regeneration behaviour that aren't not easy to fix. Background and relevant bugs:

You can try using the 'polling' method: https://github.com/guard/listen#listen-adapters instead, but it's much slower.

Upvotes: 2

Virtua Creative
Virtua Creative

Reputation: 2113

Try this to your _config.yml:

keep_files: [node]

where node is a folder to exclude from the --watch. What this will do is keeping the folder node untouched by jekyll build. Then add all files that you want to keep in the site root but not rendered by Jekyll.

Upvotes: 2

Jabran Rafique
Jabran Rafique

Reputation: 363

The value for exclude parameter in _config.yml should be an array i.e.

exclude: ['_site', 'node_modules', ...]

Source: Jekyll Documentation - Configuration

Upvotes: 3

Related Questions