The documentation is a bit unclear about this, and how nestjs currently ( version 10.2.2) implements the copying of assets is not very logical.
What to keep in mind is that assets will ONLY be copied from your source (normally src) folder.
Let's say that you have a folder named assets in your src folder, and you want to include it in your dist/src folder. You would then assume that a nest-cli.json like the one below would copy that same folder to dist/src/assets:
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": ["assets/**/*"]
]
}
}
But the above settings will instead copy the assets folder to the root of your dist folder. It will not be put in the dist/src folder, which will break any relative linking to these files from other files in your dist folder.
So, if you want to maintain the same structure in your dist folder, the proper way to do this is like this:
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [
{
"include": "assets/**/*",
"outDir": "dist/src/"
}
]
}
}
The above settings will copy all files and folders from src/assets to dist/src/assets.
{"command": "cp -R ./apps/backend/src/assets ./dist/apps/backend/src/assets"}
in commands when you are building your app withnx:run-commands
– Agony