Search code examples
typescriptbuildnestjs

How to copy non-ts files to dist when building typescript?


I have Mail module in folder with this structure:

- Mail
  - templates
      - <Handlebars files>
  - mail.module.ts

When I build (compile) TypeScript project, my template folder is not included in build folder. How to move those kind of files into dist when building?

Is it different for development vs production builds?


Solution

  • You can also do this by adding an asset property in the nest-cli.json as mentioned in the documentation.

    For your case, you can try something like this:

    "assets":["**/Mail/templates/*"]
    

    Or if your templates all have a specific filetype (I am assuming its called .template), this should also work:

    "assets":["**/*.template"]
    

    The 2nd example will copy all files of type .template from all sub directories to your dist folder with the same folder structure when you run a nest build. Similarly, you can use this to copy any filetype of your choice (.json, .proto, etc) by replacing .template in the glob pattern.