NestJS - exclude folder under watch mode

Viewed 9251

I created a public folder within root directory to store user uploaded files. But under npm run start:dev mode, every time I upload a file, Nest has detected file change and restarts server. How can I do to avoid this? Thanks.

Dir structure:

-project
 -dist
 -src
 -public
 -(other files)
6 Answers

Under tsconfig.json include the below property immediately after exclude property

  "include": [ "src"]

Inside tsconfig.json file do what I did in the bellow sample:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "paths": {

    }
  },
  "exclude": [
    "node_modules",
    "dist",
    "public"   <<-- Add the folder name here to exclude from updates
  ]
}

Insert the following in tsconfig.json:

...,
  "include": ["src"],
  "exclude": [
    "node_modules",
    "dist",
    "public"
  ]

Just add

  "watchOptions": {
    "excludeFiles": ["yourfile"]
  }

to your tsconfig.json.

I tried to do the same thing as the other answers but instead, tsconfig.build.json

{
  "extends": "./tsconfig.json",
  "exclude": ["node_modules", "test", "dist", "**/*spec.ts","uploads"]
}

Added uploads folder and it worked for me

Nothing from above helped so I post my solution. Except "include" and "exclude" in tsconfig.json in case of nest, if you have assets property defined in nest-cli.json, exclude in tsconfig won't work. You can't both watch assets in nest-cli.json and ignore them in tsconfig.

My INVALID nest-cli.json:

{
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "assets": [
    {
      "include": "frontend/dist/**",
      "watchAssets": false,
      "exclude": ["frontend/node_modules", "frontend/src"]
    }
  ]
}

so when I tried to use "exclude": ["frontend"] in tsconfig it didn't work.

Related