Why does Angular build create files with 'es5' and 'es2015' but not 'es6' (or no suffix at all)?

前端 未结 3 1325
花落未央
花落未央 2021-02-19 05:43

I recently downloaded the Angular CLI (@angular/cli 9.0.1). I then proceeded to create a new application so that I could create a new Angular Element, package it up

3条回答
  •  清酒与你
    2021-02-19 06:43

    Angular doesn't bundle the JavaScript files into a single file.

    You can add a build step to concat the files together.

    concat-build.js:

    var concat = require('concat');
    const es5 = ['./dist/app/runtime-es5.js','./dist/app/polyfills-es5.js','./dist/app/main-es5.js'];
    const es2015= ['./dist/app/runtime-es2015.js','./dist/app/polyfills-es2015.js','./dist/app/main-es2015.js'];
    concat(es5, './dist/app/elements-es5.js');
    concat(es2015, './dist/app/elements-es2015.js');
    

    package.json:

    "scripts": {
       "concat": "./concat-builds.js",
       "build": "ng build --prod --output-hashing=none && npm run concat"
    }
    

    Don't get confused by the ES5 and ES2015 builds, because the Angular team split the bundles depending upon how modules are loaded (not specifically on the JavaScript version).

    Web browsers that support modules will load the ES2015 versions instead of the ES5 versions, but both are recommended to be in the Html.

    If you want only a single file to use, then you're forced to use the older ES5 version, and should provide it as follows:

    
    
                                     
                  
提交回复
热议问题