Angular 2 with CLI - build for production

后端 未结 9 1861
夕颜
夕颜 2021-02-01 16:18

I have freshly installed angular-cli 1.0.0.beta.17 (latest one), start new project, able to serve project on port 4200 with no problems - just standard \"app works!\" message.

9条回答
  •  [愿得一人]
    2021-02-01 16:59

    There are a lot of commands to build the angular application to production mode using angular cli.

    ng build --env=prod

    Once you will execute this command on cmd dist default folder will create that will contain all the minified files related to prod build, but it will not set the base path in the index.html. To change in index.html either go and do the manual change like adding the (.) ie.

    
    

    You can also pass the parameter while building the code in prod mode using angular/CLI command.

    ng build --base-href=./ --env=prod
    

    There are other commands as well to build like passing the AOT and build-optimizer ( to reduce bundle sizes).

    ng build --prod --build-optimizer
    

    If you want to change the default folder name (dist) after build then you can change the outDir value in the .angular-cli.json.

提交回复
热议问题