M-Zuber / npm-watch

run npm scripts when files change
MIT License
323 stars 38 forks source link

Script not rerunning #92

Closed quantuminformation closed 4 months ago

quantuminformation commented 1 year ago

I have this npm script:

"dev": "cross-env NODE_ENV=development npm run build:i18n:dev && vite",

I want this script to stop and rerun if my src/i18n dir has a file change:

I tried:

  "watch": {
    "dev": "{src/i18n}/*.ts"
  },

but when I change src/i18n/en.ts I don't get what I want

nsallis commented 1 year ago

Seeing this too. Even when watching just one file. In my case it is a file in node_modules

duvalale commented 1 year ago

Same behaviour for me, no error when running the watch script, but no rerun of my script

duvalale commented 1 year ago

My bad, i finally made it work !

bonafideduck commented 11 months ago

This tool uses nodemon under the hood and nodemon, by default, only triggers on .js, .mjs, .coffee, .litcoffee, and .json. My package.json configuration is this:

{
   ...
  "watch": {
    "run_dev": {
      "patterns": [
        "src",
        "public"
      ],
      "extensions": [
        "css",
        "d",
        "js",
        "json",
        "png",
        "svg",
        "ts"
      ]
    }
}

I got the list of extensions for my public and src directory like this:

ls src/* public/* | cut -d. -f2 | sort -u
M-Zuber commented 4 months ago

Slightly out of date as to what the defaults of nodemon are, but please set the patterns and extensions keys in order to watch non-default file types

If you need to watch files with extensions other than those that nodemon watches by default (.js, .coffee, .litcoffee), you can set the value to an object with patterns and extensions keys. You can also add an ignore key (a list or a string) to ignore specific files. Finally, you can add a quiet flag to hide the script name in any output on stdout or stderr, or you can use the inherit flag to preserve the original's process stdout or stderr. You can enable nodemon legacy watch and specify the restart delay in milliseconds with the corresponding flags.