微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular 2 Typescript编译器复制html和css文件

在Angular2我会有
"outDir": "dist/app"

在tsconfig.json.因此,在/ dist / app /文件夹和/或其子文件夹中生成了.iled和.map文件.这一切都很好.

在我的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编译器只适用于* .ts文件.

您必须使用复制方法(例如cpm shell命令)复制其他文件,如* .html和* .css,例如npm脚本或grunt-contrib-copy.

使用npm脚本的示例:

"scripts": {
  "html": "find ./app -name '*.html' -type f -exec cp --parents {} ./dist \\;"
}

只需运行npm在shell中运行html.

使用grunt的例子:

copy: {
      html: {
          src: ['**/*.html'],dest: 'dist',cwd: 'app',expand: true,}
}

原文地址:https://www.jb51.cc/angularjs/142966.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐