【问题标题】:Using Angular-CLI build to copy a file / directory使用 Angular-CLI 构建复制文件/目录
【发布时间】:2016-11-12 20:43:04
【问题描述】:

有没有办法让 angular-cli 的 ng buil --prod 命令也将文件/目录复制到 dist 文件夹?

我的项目包括一个“server”文件夹和一个根目录下的“config.js”文件,我需要将它们复制到“dist”,这样在构建时,我不需要记住复制这些目录

【问题讨论】:

    标签: angular-cli


    【解决方案1】:

    对于那些想要在src 文件夹之外复制文件的人:

    在下面的示例中,我将所有文件从 myfolder 复制到根 dist 文件夹。

    在 angular-cli.json 文件中(第 3 行):

    "assets": [
       { "glob": "**/*", "input": "./assets/", "output": "./assets/" },
       { "glob": "favicon.ico", "input": "./", "output": "./" },
       { "glob": "**/*", "input": "../myfolder", "output": "./" }
    ],
    

    Angular-cli.json Documentation here

    【讨论】:

    【解决方案2】:

    在资产对象上的 angular-cli.json 上添加要包含的文件夹,例如:

    注意:对于 Angular 9,这应该放在 angular.json 文件中

    "assets": [
        "assets",
        "favicon.ico",
        "META-INF",
        "WEB-INF"
      ]
    

    【讨论】:

    • 我正在尝试复制一个目录,但它没有被复制该目录在src 文件夹之外,所以我将路径指定为../my_dir,然后我运行命令ng build --prod,并且只运行@ 987654325@ 和 favicon.ico 已复制到 dist 文件夹 my_dir 文件夹未复制。
    • 我和@HirenParekh 有同样的问题。有什么解决办法吗?
    • 对于 Angular 9,这应该放在 angular.json 文件中
    • angular.json 中的服务器构建部分不允许复制资产,因为他们假设只有浏览器构建(SPA)应该有资产。如果您正在构建一个 Angular 通用应用程序,您将面临这个问题,仍在寻找一个好的解决方案。
    【解决方案3】:

    来源Link

    对于 ng build,使用 "postbuild" 命令复制文件夹/文件

    更新 package.json 文件

    来自

    "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    ....
    

    },

    收件人

    "scripts": {
       "ng": "ng",
       "start": "ng serve",
       "build": "ng build && npm run postbuild",
       "postbuild":"xcopy /s \".\/dist\\angular-material-bottom-sheet-app\" \".\/mydistapp\\dist\" \/Y",
       "test": "ng test",
       "lint": "ng lint",
       "e2e": "ng e2e"
    },
    

    查看完整详情here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      相关资源
      最近更新 更多