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?
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.
TS compiler doesn't handle files that are other than TypeScript or JS (e.g. .ts
, .js
, .tsx
, etc.).
One way of doing it, just running cp
to copy those files after you compile NestJS. In your package.json
replace the line
"build": "nest build",
with
"build": "nest build && cp ./Mail/templates ./build",
Ideally, I would switch to Webpack (or similar) to transpile TypeScript and copy artifacts. NestJs has a basic example on how to build with Webpack here. To extend it to have a "copy" phase, install copy-webpack-plugin
npm package and add those additions in webpack config file:
const copyFiles = require('copy-webpack-plugin'); // ... omitted for abbreviation module.exports = function(options) { return { // ... omitted for abbreviation , plugins: [ // ... omitted for abbreviation new copyFiles([ { from: 'Mail/templates', to: 'templates' } ]) ] }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With