Angular run AOT + Rollup compilation with ng serve?

391 views Asked by At

I have following script in my angular2 project, usually when I want to run project the command I use will be ng serve... (start-prod, start-uat, start-dev)

However, after I read about AOT https://angular.io/guide/aot-compiler#workflow-and-convenience-script I try to follow the step and don't know how to start application because, ng serve is only thing I used at the beginning.

what script should I use to start ?

  "scripts": {
    "ng": "ng",
    "start-prod": "ng serve --environment=prod --deploy / --proxy-config proxy.conf.json",
    "start-uat": "ng serve  --environment=uat --deploy / --proxy-config proxy.conf.json",
    "start-dev": "ng serve  --environment=dev --deploy / --proxy-config proxy.conf.json",
    "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
    "build-prod": "ng build  --environment=prod --aot false output-hashing none --deploy /",
    "build-uat": "ng build  --environment=uat --aot false output-hashing none --deploy /",
    "build-dev": "ng build  --environment=dev --aot false output-hashing none --deploy /",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

Also, I want to run AOT with ngc not AOT from web pack, I have issues on using custom decorator https://github.com/rangle/angular-2-aot-sandbox and I want to try this build on production

2

There are 2 answers

1
Manu On

You can run:

ng build -prod

This will create files in your dist folder that will be aot build.

aot is by default in prod. so specifying --aot doesn't make any effect. see this answer.

1
Pardeep Jain On

To make your project running you can simply fire ng serve or ng serve --aot command

Basically at the time of creating build we will use aot along with prod to minimize the size of your bundle in the production use.

These are the various command provided by angular team you run with ng .

"scripts": {
    "ng": "ng",
    "start-prod": "ng serve --environment=prod --deploy / --proxy-config proxy.conf.json",
    "start-uat": "ng serve  --environment=uat --deploy / --proxy-config proxy.conf.json",
    "start-dev": "ng serve  --environment=dev --deploy / --proxy-config proxy.conf.json",
    "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
    "build-prod": "ng build  --environment=prod --aot false output-hashing none --deploy /",
    "build-uat": "ng build  --environment=uat --aot false output-hashing none --deploy /",
    "build-dev": "ng build  --environment=dev --aot false output-hashing none --deploy /",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

like ng serve , ng serve --aot --prod etc