How to globally set preserveWhitespaces in Angular to false?

Since it is one of the beta versions of version 5, Angular has a new compiler option, preserveWhitespaces . The property is referred to in CompilerOptions type alias in documents. The documents for the Component decorator describe its use and note that version 5 is true by default (without removing spaces).

I have seen PR , but from what I can say from some tests, is that the only way to use it is t24> for all @Component metadata. How can I set it to false globally for all components, and then set it to true only for some components?

+8
angular
source share
1 answer

By default this will be false starting from angular 6

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

main.ts

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

For aot, we must 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 an example where you can find the corresponding commit

There is also a function request in angular-cli repo.

+16
source share

All Articles