Troels Larsen
Troels Larsen

Reputation: 4631

Node - set angular-cli environment

I'm deploying my angular-cli app through node. Rather than ng serve --prod, I use npm start.

Is there any way to achieve the --environment=prod setting from npm so that it will use environment.prod.ts instead of environment.ts?

My Dockerfile:

FROM node
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
EXPOSE 4200
CMD ["npm", "start"]

Top of package.json:

{
  "name": "asgard2",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
},
[...] 

To start in production, I can run:

ng serve --prod

But I can't do:

npm start --prod

Or at least, when I do, it is still deployed as debug. It is very likely that I am doing something wrong in my deployment.

Upvotes: 1

Views: 586

Answers (2)

JB Nizet
JB Nizet

Reputation: 691715

As far as I understand, you want to deploy your application to a real, production web server.

Use ng build --prod. That generates a set of static files under the dist directory, that can be served by any web server able to serve static files.

Install a production web server (like Apache, or Nginx for example) in your docker container, and make it serve those static files.

You can also use a node-based web server if you want, but if the goal is just to serve static files, I don't really see the point, and Apache or Nginx will probably be more efficient.

Upvotes: 1

Ty Sabs
Ty Sabs

Reputation: 229

You could go into your environment.ts file and change

export const environment = {
  production: false
};

to

export const environment = {
  production: true
};

Upvotes: 1

Related Questions