Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Babel being used as compiler (AOT or JIT) in angular 5

Do we need Babel in an Angular 5 application? What AOT or JIT is being used internally to compile?

like image 453
RK6 Avatar asked Apr 24 '18 10:04

RK6


People also ask

Does Angular use Babel?

Since Angular utilizes decorators and class properties heavily and Babel doesn't support them in those presets, we need to add them manually. Please note that plugin-proposal-decorators needs to be additionally configured — we need to use legacy decorators mode.

What is AOT and JIT compiler in Angular?

AOT. JIT downloads the compiler and compiles code exactly before Displaying in the browser. AOT has already complied with the code while building your application, so it doesn't have to compile at runtime. Loading in JIT is slower than the AOT because it needs to compile your application at runtime.

Which compiler is used in Angular?

The Angular Compiler (which we call ngc ) is the tool used to compile Angular applications and libraries. ngc is built on the TypeScript compiler (called tsc ) and extends the process of compiling TypeScript code to add additional code generation related to Angular's capabilities.

What is Babel compiler used for?

Babel is a JavaScript compiler Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.


1 Answers

You don't need to worry about babel in an angular 2+ application.

You configure the ECMAscript level in the tsconfig.app.json file in you project.

(be sure you initiated your project with angular's angular-cli)

example (angular 8):

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

example (angular 5) :

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015", //<-- can aslo be es5 es6 es7
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

typescript, angular's filesystem includes a very complete bundle of all the other goodies there exist in the JS biosphere :

  • ECMAscript (ergo babel)
  • coffeescript
  • ...
like image 153
tatsu Avatar answered Oct 04 '22 01:10

tatsu