npm run 未通过 --configuration 来构建任务

Jos*_*rán 6 npm docker dockerfile angular-cli angular

ng build我在运行命令时遇到问题npm run。我有以下场景:

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

  • \n
  • 另一方面,当我构建 Docker 映像时,我使用运行命令,npm rum ng build --configuration=$VAR但未传递参数,结果也不是预期的。

  • \n
\n\n

虽然我认为没有必要,但我的 Dockerfile 如下

\n\n
# STAGE 1: Build\n##############################################################################\n\n# Image\nFROM node:10-alpine as builder\nMAINTAINER joseantonio@gogroup.es\n\n# BUILD ARGS\nARG ENVIROMENT\n\n# Installing GIT & Bash\nRUN apk add --no-cache git\n\n## Storing node modules on a separate layer will prevent unnecessary npm installs at each build\nCOPY package.json package-lock.json ./\nRUN npm ci\nRUN mkdir /pancho-ui\nRUN mv ./node_modules ./pancho-ui\nWORKDIR /pancho-ui\nCOPY . .\n\n## Build the angular app in production mode and store the artifacts in dist folder\nRUN npm run ng build --output-path=dist --configuration=$ENVIROMENT --verbose\n\n# STAGE 2: Setup\n##############################################################################\n\n# Image\nFROM nginx:1.14.1-alpine\nMAINTAINER joseantonio@gogroup.es\n\n## Copy our default nginx config\nCOPY nginx/default.conf /etc/nginx/conf.d/\n\n## Remove default nginx website\nRUN rm -rf /usr/share/nginx/html/*\n\n## From \xe2\x80\x98builder\xe2\x80\x99 stage copy over the artifacts in dist folder to default nginx public folder\nCOPY --from=builder /pancho-ui/dist /usr/share/nginx/html\nRUN mv /usr/share/nginx/html/pancho-ui/* /usr/share/nginx/html/\n\n# Run nginx\nCMD ["nginx", "-g", "daemon off;"]\n
Run Code Online (Sandbox Code Playgroud)\n

Jos*_*rán 22

最后我在这篇文章中找到了我的问题的解决方案。

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

就我而言,我需要改变

RUN npm run ng build --output-path=dist --configuration=$ENVIROMENT --verbose
Run Code Online (Sandbox Code Playgroud)

到

RUN npm run ng build -- --output-path=dist --configuration=$ENVIROMENT --verbose
Run Code Online (Sandbox Code Playgroud)