undefined
undefined

Reputation: 2119

NestJS prevent server reloading in development

I have a route which creates a new folder inside public directory which is a static content served with app.useStaticAssets.

The problem is that even if I added the public directory inside exclude array of both tsconfig.build.json and tsconfig.json, my server still reloads in development when a new folder is deleted or created inside public directory.

I'm missing something ?

UPDATE: tsconfig.json

{
 "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "noImplicitAny": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  },
  "exclude": ["node_modules", "dist", "public"]
}

I mention that public folder is outside of the src folder. They are on the same level.

Upvotes: 2

Views: 2095

Answers (2)

Marian
Marian

Reputation: 1

If you want to completely disable hot reload temporarily, remove the --watch flag from your start:dev script.

  1. Go into package.json
  2. Find your "start:dev" script under "scripts"
  3. Duplicate your "start:dev" script and rename it - I named it start:dev-noreload Your script should look something like this:

"start:dev-noreload": "npm run prebuild && npm run kill:dev-process && npm run build:docker-postgres && env ENV=DEV nest start"

  1. Run your app using

    npm run start:dev-noreload

In order to get hot reload back, just run the way you normally do. Either using npm start, or npm run start:dev.

Upvotes: 0

eol
eol

Reputation: 24555

I was able to reproduce this and found out that this seems to be a common issue -> https://github.com/nestjs/nest/issues/3510

As propsed in the github issue, adding include as a workaround seems to fix the problem:

{
 "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "noImplicitAny": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "esModuleInterop": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist", "public"]
}

Upvotes: 5

Related Questions