Jak*_*ake 2 node.js handlebars.js typescript babeljs npm-scripts
我使用的是 Typescript,它从src/到lib/文件夹进行编译,而 Babel,它从lib/到进行编译dist/。
我遇到的问题是,当我编译应用程序时,.handlebars其中的文件src/email_templates/没有被复制到。dist/因此,当我运行该应用程序时,它会失败并出现错误,因为它dist/email_templates/不存在。
我正在使用nodemailer-handlebars包并尝试将email_templates/文件夹移动到项目根目录并设置viewPath为该文件夹,但是这也会失败,因为应用程序位于var/www/api.my-domain.com/. 似乎api.my-domain.com文件夹名称中有句点会导致 viewPath 失败并出现错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at validateString (internal/validators.js:125:11)
at Object.resolve (path.js:1080:7)
at ExpressHandlebars._resolveLayoutPath (/var/www/api.my-domain.com/node_modules/express-handlebars/lib/express-handlebars.js:342:17)
at ExpressHandlebars.<anonymous> (/var/www/api.my-domain.com/node_modules/express-handlebars/lib/express-handlebars.js:223:35)
Run Code Online (Sandbox Code Playgroud)
这是我用于构建应用程序的 package.json 脚本:
"build": "tsc && babel ./lib --out-dir ./dist ",
Run Code Online (Sandbox Code Playgroud)
我如何更改它,以便删除当前内容,dist/email_templates然后将内容复制src/email_templates到dist/email_templates?
使用 cpx 包解决:https://www.npmjs.com/package/cpx
npm install cpx --save-dev
Run Code Online (Sandbox Code Playgroud)
包.json:
- "build": "tsc && babel ./lib --out-dir ./dist",
+ "build": "tsc && babel ./lib --out-dir ./dist && cpx \"./src/email_templates/**/*\" ./dist/email_templates --clean",
Run Code Online (Sandbox Code Playgroud)
npm run build
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3126 次 |
| 最近记录: |