Dragouf
Dragouf

Reputation: 4734

angular6: add universal support with cli

I created a new angular6 application using angular cli and then type :

ng generate universal

to add universal support.

I works fine but I wonder why it added

"server": {
  "builder": "@angular-devkit/build-angular:server",
  "options": {
    "outputPath": "dist/VulogDeploy-server",
    "main": "ClientApp/main.server.ts",
    "tsConfig": "ClientApp/tsconfig.server.json"
  }
}

inside angular.json file. Is there another cli command to generate server app ?

What I try to have a look to the doc I see they are creating a webpack config file and use a webpack command to generate server app.

what is the good way to continue after execution of the ng generate universal command ?

Upvotes: 1

Views: 413

Answers (1)

David
David

Reputation: 34435

I'd say you first need to compile the server app using the following command

ng run [appName]:server 

which will create and copy the the server bundle inside the specified folder (dist/VulogDeploy-server in your case)

Then, you need to setup the universal webserver with nodejs/express and webpack. You use webpack to compile your server.ts, which will use the app bundle created in the first step to do the rendering

The wiki stories have not been updated for angular 6 yet https://github.com/angular/angular-cli/wiki/stories-universal-rendering, but I guess the principle remains the same

Upvotes: 3

Related Questions