How to get one file as output of angular cli

前端 未结 5 785
自闭症患者
自闭症患者 2020-12-08 14:24

I\'m working on ng2 application and I use @angular/cli to build it. As output it emits several js files like .inline.js, .vendor.js et

5条回答
  •  醉梦人生
    2020-12-08 15:14

    I have not seen any functionality in angular-cli that builds into one bundle, however, it should be fairly easy to do with a nodejs script or using one of the concat libraries available such as concat-files https://www.npmjs.com/package/concat-files

    install concat-files then: add a concat.js file in your project at the same level as dist folder

    var concat = require('concat-files');
    concat([
        './dist/inline.bundle.js',
        './dist/vendor.bundle.js',
        './dist/vendor.bundle.js'
    ], './dist/app.js', function(err) {
        if (err) throw err
        console.log('done');
    });
    

    in your package.json under scripts add a new script build:

    "scripts":{
        "build": "ng build && node concat.js"
    }
    

    then run it npm run build it will run the angular cli build first the run the concat.js script which will concatenate the resulting bundles

提交回复
热议问题