Skip to content

Only watch specified directory (--watch CLI param) #787

Open

Description

@nimble-turtle

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Allow a directory (or list of directories) to be passed into the --watch param

Motivation

In my project, I have a small API subfolder. When I turn on --watch, it is monitoring my entire project root for changes, which leads to resets constantly.

Example

Right now the only solution is to do something like this:

fastify start --watch --ignore-watch '.git node_modules out .next content public scripts utils styles pages config compontents' --log-level info --pretty-logs --port ${API_PORT:-4321} api/server.js

I would rather do this:

fastify start --watch api --log-level info --pretty-logs --port ${API_PORT:-4321} api/server.js

Activity

  1. mcollina commented on Dec 23, 2024

    @mcollina
    Member

    Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

  2. jean-michelet commented on Dec 23, 2024

    @jean-michelet
    Member

    Good idea @ActivistChecklist,

    Maybe look at the ignore-watch related code to take inspiration and do it the other way.

  3. EmilianoBruni commented on Feb 16, 2025

    @EmilianoBruni

    I've gone crazy with Watch and the problem is the code below that is crazy (and obviously undocumented)

    I needed to watch only in "dist". But nothing work. And now I know why. Because fastify add dist by default. But if I ignore ".ts$", voilà 👎

    Ok if I don't set anything but I think that if I set ignore-watch I know what folders I want to exclude.

    From: https://github.com/fastify/fastify-cli/blob/590f350d1a586f68e78ecc72a8cc1b17ce1507a0/args.js#L7C1-L7C93

    const DEFAULT_IGNORE = 'node_modules build dist .git bower_components logs .swp .nyc_output'
    .....
    let ignoreWatch = `${DEFAULT_IGNORE} ${ignoreWatchArg}`.trim()
      if (ignoreWatchArg.includes('.ts$')) {
        ignoreWatch = ignoreWatch.replace('dist', '')
      }
  4. gulbaki commented on Jun 21, 2025

    @gulbaki

    Is this task still active? I noticed a PR has been opened but not reviewed yet. #794
    If it's still ongoing, I'd be happy to take it on.
    @mcollina @jean-michelet

  5. mcollina commented on Jun 21, 2025

    @mcollina
    Member

    Yes, I think so! I'm sorry I missed the original PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions