简体   繁体   English

节点-设置angular-cli环境

[英]Node - set angular-cli environment

I'm deploying my angular-cli app through node. 我正在通过节点部署我的angular-cli应用程序。 Rather than ng serve --prod , I use npm start . 而不是ng serve --prod ,我使用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 ? 有什么办法可以从npm中实现--environment=prod设置,以便它将使用environment.prod.ts而不是environment.ts

My Dockerfile: 我的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: 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. 我很可能在部署中做错了事。

You could go into your environment.ts file and change 您可以进入您的environment.ts文件并进行更改

export const environment = {
  production: false
};

to

export const environment = {
  production: true
};

As far as I understand, you want to deploy your application to a real, production web server. 据我了解,您希望将应用程序部署到真实的生产Web服务器上。

Use ng build --prod . 使用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. 这将在dist目录下生成一组静态文件,任何能够提供静态文件的Web服务器都可以提供该文件。

Install a production web server (like Apache, or Nginx for example) in your docker container, and make it serve those static files. 在Docker容器中安装生产Web服务器(例如Apache或Nginx),并使其提供那些静态文件。

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. 如果需要,您也可以使用基于节点的Web服务器,但是如果目标只是提供静态文件,我看不出重点,Apache或Nginx可能会更高效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM