加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 07:44:29 所属栏目:安全 来源:网络整理
导读:在Angular2我会有 "outDir": "dist/app" 在tsconfig.json.因此,在/ dist / app /文件夹和/或其子文件夹中生成了.iled和.map文件.这一切都很好. 在我的components.ts文件中,我也使用了这样引用的html和css @Component({ selector: 'my-app',templateUrl: 'app
在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 .distapp" }
不,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,}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读