我构建了一个具有以下文件结构的应用程序:
我正在为此应用程序使用 Typescript 和 Angular2。我在 .ts 文件上有观察者,当有任何变化时,typescript 文件 会自动编译。 .ts 文件位于 /assets/app
文件夹中,转译后的 .js 文件的输出目录是/public app 文件。
这工作正常,但是当对任何 .html 文件进行增删改查时,我必须直接在 /public/app
文件中编辑这些文件,因为它们是 .html 而不是 . ts 文件。
我想知道(作为 Angular2 和 Typescript 的新手)是否有任何方法可以让 html View 文件在创建和更新时自动移动到公共(public)文件夹?
这是我当前的 npm 命令,它监视 NodeJS 和 .ts 文件的变化:
"start": "concurrently \"tsc -w \" \"nodemon ./bin/www\"",
谢谢
最佳答案
要解决此问题,您可以将 html 文件保存为以下格式:
fileName.html.ts
在那里,将整个 html 定义为:
export const html: string= `<div> something </div>`;
要在指令中获取此 html,您可以将其用作:
import {html} from 'fileName.html'
代替 templateUrl,您应该使用模板作为:
template: html
更多信息可以看this repo在知乎上
希望这能解决您的问题。
关于node.js - 输出到另一个目录时,如何在 Typescript 编译过程中包含 .html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38264466/