【问题标题】:npm run doesn't pass --configuration to build tasknpm run 不通过 --configuration 来构建任务
【发布时间】:2019-09-16 17:51:29
【问题描述】:

我在运行来自npm runng build 命令时遇到问题。我有以下几种情况:

  • 当我在本地环境中构建项目时,我运行 ng build --configuration=development,一切正常。

  • 另一方面,当我构建我的 Docker 映像时,我使用 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;"]

【问题讨论】:

    标签: angular docker npm dockerfile angular-cli


    【解决方案1】:

    最后我在post 中找到了我的问题的解决方案。

    我的npm run 语法不正确。将参数传递给npm 命令的正确方法是添加-- 运算符。

    就我而言,我需要改变

    RUN npm run ng build --output-path=dist --configuration=$ENVIROMENT --verbose
    

    RUN npm run ng build -- --output-path=dist --configuration=$ENVIROMENT --verbose
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2017-02-27
      相关资源
      最近更新 更多