【发布时间】:2016-12-07 02:03:48
【问题描述】:
在 Angular2 中我会有
"outDir": "dist/app"
在 tsconfig.json 中。结果,转译的 .js 和 .map 文件在 /dist/app/ 文件夹和/或其子文件夹中生成。一切正常。
在我的 components.ts 文件中,我还使用了像这样引用的 html 和 css
@Component({
selector: 'my-app',
templateUrl: 'app/appshell/app.component.html',
styleUrls: ['app/appshell/app.component.css'],
......
}
有没有办法让编译器也复制整个项目的引用的html和css文件? 如果是,我将如何配置我的 tsconfig.json?
我在这里查看了编译器选项https://www.typescriptlang.org/docs/handbook/compiler-options.html,但没有找到任何关于复制 html/css 文件的信息。
更新: 我的文件夹结构是这样的
Root
|--app // for ts
|--dist/app // for js
tsconfig.json
"outDir": "dist/app"
package.json
{
"name": "TestApp",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"html": "find ./app -name '*.html' -type f -exec cp --parents {} ./dist \\;",
......
}
它不会复制 html 文件。不过没有错误。
再次更新:
对于那些使用 Linux 操作系统的人来说,Bernardo 的解决方案是可行的。 对于那些使用 Windows 操作系统的人,以下应该可以工作。
"scripts": {
"html": "XCOPY /S /y .\\app\\*.html .\\dist\\app" }
【问题讨论】:
-
只是为了让你接触到你可能没有考虑过的生态系统,它很容易用 TypeScript+React+FreeStyle (medium.com/@basarat/…) 将今天的任何东西打包成 JS ????
-
xcopy已弃用。一个不错的选择是"static": "robocopy app dist\\app *.html *.css /e /purge"和"build": "npm run start && npm run static"。因此,您可以一步构建整个应用程序,也可以单独构建。
标签: typescript angular