【问题标题】:Copy artifacts generated by ng build in outdir to another folder将 ng build in outdir 生成的工件复制到另一个文件夹
【发布时间】:2020-12-15 23:03:24
【问题描述】:

我有一个角度项目。当我们运行 ng build 命令时,会在 dist 文件夹中创建构建工件,因为我们在 angular-cli.json 中设置了"outDir": "dist",。在此之后,我必须手动将这些文件从 dist 复制到 java 的 Webcontent 文件夹以生成 WAR 文件。

有没有办法自动化处理工件的过程。如果我将 WebContent 的路径设置为 outDir 值 "outDir": "../server/WebContent", ,则构建命令会在生成构建工件之前清理现有的 java 文件。

任何建议都会有所帮助..

【问题讨论】:

    标签: node.js angular npm angular-cli ng-build


    【解决方案1】:

    考虑以下解决方案:

    1. 在您的项目 package.json 文件中添加一个名为 buildnpm script 以执行您的 ng build 命令。
    2. 另外添加一个名为 postbuildpost hook npm 脚本来复制您的文件。

    下面描述了如何在一个*Nix平台上实现这一点,同时也提供了一个跨平台的解决方案。


    *Nix (Linux, macOS, ...)

    在 *nix 平台上,npm 使用 sh 作为运行 npm 脚本的默认 shell。因此,将以下内容添加到您的项目 package.jsonscripts 部分:

    包,json

    "scripts": {
      "build": "ng build",
      "postbuild": "cp -r dist/ ../server/WebContent"
    }
    

    这个 postbuild npm 脚本利用 shells cp 命令递归地将工件从 dist 目录复制到 ../server/WebContent 目录。 postbuild 脚本将在build 脚本成功完成后自动运行。

    跑步:

    通过您的命令行运行以下命令而不是 ng build:

    npm run build
    

    跨平台(Linux、macOS、Windows...)

    对于跨平台解决方案,首先安装 shx - 它是 ShellJS Unix 命令的包装器:

    1. cd 到您的项目目录。

    2. 然后运行以下命令:

      npm install -D shx
      

    如下定义项目package.jsonscripts部分:

    package.json

    "scripts": {
      "build": "ng build",
      "postbuild": "shx cp -r \"dist/*\" \"../server/WebContent\""
    }
    

    跑步:

    通过您的命令行运行以下命令而不是 ng build:

    npm run build
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      • 2011-08-22
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      相关资源
      最近更新 更多