I want to understand the difference between ES2015 and ESM2015. I know that ES2015 is the ES^ standards but recently while compiling my Angular application using ng build
I got the following : Compiling @angular/core : es2015 as esm2015
I want to know why ESM2015? Is it minified ES2015 files?
In case you are wondering about terminology, ESM2015 is a pure ES2015 (ES6) distribution of Angular. ESM5 is a hybrid format consisting mostly of regular ES5 JavaScript, but with import/export statements added as the only ES2015 feature.
The shortened name "FESM" (pronounced "phesom") can have a number after it such as "FESM5" or "FESM2015". The number refers to the language level of the JavaScript inside the module. So a FESM5 file would be ESM+ES5 (import/export statements and ES5 source code).
According to the documentation for Angular Package Format:
Short for ECMAScript Modules. A file containing statements that import and export symbols. This is identical to the definition of modules in the ECMAScript spec.
When a project is compiled from es2015 to esm2015, like Compiling @angular/core : es2015 as esm2015
Basically it is still EcmaScript, but esm is based on modules "or packages", this allows to make some parts of the code independent from others.
Other differences between modules and standard scripts:
- modules use strict mode automatically.
- modules are deferred automatically (when are loading).
- Modules are only executed once, even if they have been referenced in multiple tags.
- Modules features are imported into the scope of a single script — they aren't available in the global scope.
more info here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With