我无法从ng build
运行npm run
命令。我有以下几种情况:
当我在本地环境上构建项目时,我运行ng build --configuration=development
,一切正常。
另一方面,当我构建Docker Image时,我使用npm rum ng build --configuration=$VAR
运行命令,并且未传递参数,并且结果并非预期。
尽管我认为这不是必需的,但我的Dockerfile在下面
# STAGE 1: Build
##############################################################################
# Image
FROM node:10-alpine as builder
MAINTAINER joseantonio@gogroup.es
# BUILD ARGS
ARG ENVIROMENT
# Installing GIT & Bash
RUN apk add --no-cache git
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
COPY package.json package-lock.json ./
RUN npm ci
RUN mkdir /pancho-ui
RUN mv ./node_modules ./pancho-ui
WORKDIR /pancho-ui
COPY . .
## Build the angular app in production mode and store the artifacts in dist folder
RUN npm run ng build --output-path=dist --configuration=$ENVIROMENT --verbose
# STAGE 2: Setup
##############################################################################
# Image
FROM nginx:1.14.1-alpine
MAINTAINER joseantonio@gogroup.es
## Copy our default nginx config
COPY nginx/default.conf /etc/nginx/conf.d/
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
COPY --from=builder /pancho-ui/dist /usr/share/nginx/html
RUN mv /usr/share/nginx/html/pancho-ui/* /usr/share/nginx/html/
# Run nginx
CMD ["nginx", "-g", "daemon off;"]
答案 0 :(得分:0)
最后,我在此post中找到了解决问题的方法。
我的npm run
的sintax是不正确的。将参数传递给npm
命令的正确方法是添加--
运算符。
就我而言,我需要更改
RUN npm run ng build --output-path=dist --configuration=$ENVIROMENT --verbose
到
RUN npm run ng build -- --output-path=dist --configuration=$ENVIROMENT --verbose