如何全局设置Angular中的preserveWhitespaces选项为false? [英] How to globally set the preserveWhitespaces option in Angular to false?

查看:374
本文介绍了如何全局设置Angular中的preserveWhitespaces选项为false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于版本5的Beta版之一,Angular具有一个新的编译器选项preserveWhitespaces.在文档中的 CompilerOptions类型别名中提到了该属性. Component装饰器的文档描述了 其用法 ,并提到版本5的默认值为true(不删除空格).

Since one of the beta releases of version 5, Angular has a new compiler option, preserveWhitespaces. The property is mentioned in CompilerOptions type alias in the docs. The docs for the Component decorator describe its usage, and mention that the default in version 5 is true (no whitespace removal).

我看过 PR ,但是从我的判断中一些测试是,使用它的唯一方法是为每个@Component元数据提供preserveWhitespace.如何为所有组件将其全局设置为false,然后仅对某些组件将其设置为true?

I've seen the PR, but from what I can tell from some tests is that the only way to use it is to supply preserveWhitespace to every @Component metadata. How can I set it to false globally, for all components, and then set it to true only for some components?

推荐答案

默认情况下,从6号角开始,这将为false

This will be false by default starting with angular 6

目前,在JIT模式下,我们可以将其设置为

For now, in JIT mode we can set it as part of CompileOptions:

main.ts

platformBrowserDynamic().bootstrapModule(AppModule, { preserveWhitespaces: false });

对于aot,我们必须将此选项添加到

For aot we have to add this option to

tsconfig.app.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ],
  "angularCompilerOptions": {
    "preserveWhitespaces": false
  }
}

Angular-cli@1.4.5示例 您可以找到相应的提交

angular-cli仓库中也有功能请求.

There is also feature request in angular-cli repo.

这篇关于如何全局设置Angular中的preserveWhitespaces选项为false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆