typescript - tsc how to copy other files type to the dist folder

Viewed 2640

Typescript compiler does not copy all files from the src folder to the dist folder. I was not able to find any useful option for the Typescript CLI.

example: if I have a png file along with a typescript file index.ts, running 'yarn tsc' will produce a dist folder with only the index.js file.

1 Answers

I was not able to find anything included in the official doc. I've ended up to have a "post-build" command in the package.json that runs a rsync command.

{
  "build": "yarn tsc",
  "postbuild": "rsync -avum --include='*.png' --include='*/' --exclude='*' './src/' './dist'"
}

The following command will copy all the png files at the same location as the src.

An alternative version is

rsync -avu --exclude={'*.ts','*.yml','*.json','*.http','*.conf','*.sh'} "./src/" "./dist"

N.B. My dist folder does not include the src folder.

Related