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.
ng serve --prodinstead of the defaultng serve? Just edit your package.json and add--prodafterng serve.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.