如何将车把文件复制到 dist 文件夹
How to copy handlebars files to dist folder
我正在使用从 src/
编译到 lib/
文件夹的 Typescript,以及从 lib/
编译到 dist/
.
的 Babel
我遇到的问题是 src/email_templates/
中的 .handlebars
个文件在我编译应用程序时没有被复制到 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)
这是我用来构建应用程序的 package.json 脚本:
"build": "tsc && babel ./lib --out-dir ./dist ",
我如何更改它以便删除 dist/email_templates
的当前内容然后将 src/email_templates
的内容复制到 dist/email_templates
?
delete the current contents of dist/email_templates then copies the contents of src/email_templates to dist/email_templates
另外两个 npm 包
- rmraf 删除 dist 文件夹中的旧文件 https://www.npmjs.com/package/rimraf
- mv 将新文件移动到 dist 文件夹 https://www.npmjs.com/package/mv
使用 cpx 包解决:https://www.npmjs.com/package/cpx
npm install cpx --save-dev
Package.json:
- "build": "tsc && babel ./lib --out-dir ./dist",
+ "build": "tsc && babel ./lib --out-dir ./dist && cpx \"./src/email_templates/**/*\" ./dist/email_templates --clean",
npm run build
我正在使用从 src/
编译到 lib/
文件夹的 Typescript,以及从 lib/
编译到 dist/
.
我遇到的问题是 src/email_templates/
中的 .handlebars
个文件在我编译应用程序时没有被复制到 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)
这是我用来构建应用程序的 package.json 脚本:
"build": "tsc && babel ./lib --out-dir ./dist ",
我如何更改它以便删除 dist/email_templates
的当前内容然后将 src/email_templates
的内容复制到 dist/email_templates
?
delete the current contents of dist/email_templates then copies the contents of src/email_templates to dist/email_templates
另外两个 npm 包
- rmraf 删除 dist 文件夹中的旧文件 https://www.npmjs.com/package/rimraf
- mv 将新文件移动到 dist 文件夹 https://www.npmjs.com/package/mv
使用 cpx 包解决:https://www.npmjs.com/package/cpx
npm install cpx --save-dev
Package.json:
- "build": "tsc && babel ./lib --out-dir ./dist",
+ "build": "tsc && babel ./lib --out-dir ./dist && cpx \"./src/email_templates/**/*\" ./dist/email_templates --clean",
npm run build