typescriptnestjsyarnpkg

nest start removes my json files from dist


when I build my nestjs application, I need certain json files to be copied to the dist. especially I have an "engines" folder, and I need the json files to be on dist/and prod, as they are in src/engines.

However, nest start removes the dist folder and recreates with only d.ts, js and js.map, and my json files are removed.

I tried to do the following in my package.json scripts:

"copy:json": "copyfiles -u 2 src/engines/**/*.json dist/engines",
"start": "nest start && yarn copy:json",
"start:dev": "nest start --watch && yarn copy:json",
"start:debug": "nest start --debug --watch && yarn copy:json",
"start:prod": "node dist/main && yarn copy:json",

I don't know why, but when I do start:dev, I still have any json file in my dist directory. The yarn copy:json alone works well (copies the right files in the right location)


Solution

  • You could add the *.json files to the assets, which get copied on build.

    eg. in your nest-cli.json:

      "compilerOptions": {
        "deleteOutDir": true,
        "assets": ["engines/**/*.json"],
        "watchAssets": true
      }
    

    Source