1

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.

9
  • Unclear. What does your npm start script does? Commented Apr 3, 2017 at 19:48
  • @JBNizet: Everything is default as set up by angular-cli, but you make a very good point. I should probably build first, then deploy and serve. Commented Apr 3, 2017 at 19:52
  • Ah, so you want npm start to do ng serve --prod instead of the default ng serve? Just edit your package.json and add --prod after ng serve. Commented Apr 3, 2017 at 19:52
  • @JBNizet: Well. I actually wanted to avoid using the NG Live Development Server due to the warning to not use it in production, so I'm trying to deploy the angular-cli app to Node.js via docker. As I don't have 'ng' available there, I wanted to start it in another way. There may be something I don't understand along the way. A lot of new stuff to learn. Commented Apr 3, 2017 at 20:02
  • So 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. Commented Apr 3, 2017 at 20:07

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You could go into your environment.ts file and change

export const environment = {
  production: false
};

to

export const environment = {
  production: true
};

1 Comment

But then I'd have the reverse prod when not in production. I guess I could copy the contents of environment.ts to environment.prod.ts during deployment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.